aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <[email protected]>2013-04-01 18:54:56 -0700
committerPaul Eggert <[email protected]>2013-04-01 18:54:56 -0700
commit7216e43b329303146455bb1dace88f8c61b1cd20 (patch)
tree900c267701eccb66398b6514816e153fb50b6a26 /src
parent4b725a70efa7ed781b6d5e466c8acc246f68f49d (diff)
Prefer < to > in range checks such as 0 <= i && i < N.
This makes it easier to visualize quantities on a number line. This patch doesn't apply to all such range checks, only to the range checks affected by the 2013-03-24 change. This patch reverts most of the 2013-03-24 change. * alloc.c (xpalloc, Fgarbage_collect): * ccl.c (ccl_driver, resolve_symbol_ccl_program): * character.c (string_escape_byte8): * charset.c (read_hex): * data.c (cons_to_unsigned): * dispnew.c (update_frame_1): * doc.c (Fsubstitute_command_keys): * doprnt.c (doprnt): * editfns.c (hi_time, decode_time_components): * fileio.c (file_offset): * fns.c (larger_vector, make_hash_table, Fmake_hash_table): * font.c (font_intern_prop): * frame.c (x_set_alpha): * gtkutil.c (get_utf8_string): * indent.c (check_display_width): * keymap.c (Fkey_description): * lisp.h (FIXNUM_OVERFLOW_P, vcopy): * lread.c (read1): * minibuf.c (read_minibuf_noninteractive): * process.c (wait_reading_process_output): * search.c (Freplace_match): * window.c (get_phys_cursor_glyph): * xdisp.c (redisplay_internal): * xsmfns.c (smc_save_yourself_CB): Prefer < to > for range checks. * dispnew.c (sit_for): Don't mishandle NaNs. This fixes a bug introduced in the 2013-03-24 change. * editfns.c (decode_time_components): Don't hoist comparison. This fixes another bug introduced in the 2013-03-24 change.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog37
-rw-r--r--src/alloc.c4
-rw-r--r--src/ccl.c4
-rw-r--r--src/character.c6
-rw-r--r--src/charset.c2
-rw-r--r--src/data.c4
-rw-r--r--src/dired.c5
-rw-r--r--src/dispnew.c4
-rw-r--r--src/doc.c2
-rw-r--r--src/doprnt.c2
-rw-r--r--src/editfns.c6
-rw-r--r--src/fileio.c2
-rw-r--r--src/fns.c12
-rw-r--r--src/font.c4
-rw-r--r--src/frame.c9
-rw-r--r--src/gtkutil.c2
-rw-r--r--src/indent.c2
-rw-r--r--src/keymap.c2
-rw-r--r--src/lisp.h4
-rw-r--r--src/lread.c12
-rw-r--r--src/minibuf.c2
-rw-r--r--src/process.c2
-rw-r--r--src/search.c6
-rw-r--r--src/window.c2
-rw-r--r--src/xdisp.c2
-rw-r--r--src/xsmfns.c2
26 files changed, 89 insertions, 52 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index b2b4aa6895..ea4e660ed8 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,40 @@
+2013-04-02 Paul Eggert <[email protected]>
+
+ Prefer < to > in range checks such as 0 <= i && i < N.
+ This makes it easier to visualize quantities on a number line.
+ This patch doesn't apply to all such range checks,
+ only to the range checks affected by the 2013-03-24 change.
+ This patch reverts most of the 2013-03-24 change.
+ * alloc.c (xpalloc, Fgarbage_collect):
+ * ccl.c (ccl_driver, resolve_symbol_ccl_program):
+ * character.c (string_escape_byte8):
+ * charset.c (read_hex):
+ * data.c (cons_to_unsigned):
+ * dispnew.c (update_frame_1):
+ * doc.c (Fsubstitute_command_keys):
+ * doprnt.c (doprnt):
+ * editfns.c (hi_time, decode_time_components):
+ * fileio.c (file_offset):
+ * fns.c (larger_vector, make_hash_table, Fmake_hash_table):
+ * font.c (font_intern_prop):
+ * frame.c (x_set_alpha):
+ * gtkutil.c (get_utf8_string):
+ * indent.c (check_display_width):
+ * keymap.c (Fkey_description):
+ * lisp.h (FIXNUM_OVERFLOW_P, vcopy):
+ * lread.c (read1):
+ * minibuf.c (read_minibuf_noninteractive):
+ * process.c (wait_reading_process_output):
+ * search.c (Freplace_match):
+ * window.c (get_phys_cursor_glyph):
+ * xdisp.c (redisplay_internal):
+ * xsmfns.c (smc_save_yourself_CB):
+ Prefer < to > for range checks.
+ * dispnew.c (sit_for): Don't mishandle NaNs.
+ This fixes a bug introduced in the 2013-03-24 change.
+ * editfns.c (decode_time_components): Don't hoist comparison.
+ This fixes another bug introduced in the 2013-03-24 change.
+
2013-03-31 Dmitry Antipov <[email protected]>
* frame.h (struct frame): Drop scroll_bottom_vpos
diff --git a/src/alloc.c b/src/alloc.c
index 0a7950273f..7a56c78e2b 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -779,7 +779,7 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
ptrdiff_t nitems_incr_max = n_max - n;
ptrdiff_t incr = max (nitems_incr_min, min (incr_estimate, nitems_incr_max));
- eassert (item_size > 0 && nitems_incr_min > 0 && n >= 0 && nitems_max >= -1);
+ eassert (0 < item_size && 0 < nitems_incr_min && 0 <= n && -1 <= nitems_max);
if (! pa)
*nitems = 0;
if (nitems_incr_max < incr)
@@ -5376,7 +5376,7 @@ See Info node `(elisp)Garbage Collection'. */)
double tot = total_bytes_of_live_objects ();
tot *= XFLOAT_DATA (Vgc_cons_percentage);
- if (tot > 0)
+ if (0 < tot)
{
if (tot < TYPE_MAXIMUM (EMACS_INT))
gc_relative_threshold = tot;
diff --git a/src/ccl.c b/src/ccl.c
index c3b3f5486c..8fec18296a 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -1668,7 +1668,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
}
map = XCDR (map);
if (! (VECTORP (map)
- && ASIZE (map) > 0
+ && 0 < ASIZE (map)
&& INTEGERP (AREF (map, 0))
&& XINT (AREF (map, 0)) <= op
&& op - XINT (AREF (map, 0)) + 1 < ASIZE (map)))
@@ -1867,7 +1867,7 @@ resolve_symbol_ccl_program (Lisp_Object ccl)
return Qnil;
}
- if (! (XINT (AREF (result, CCL_HEADER_BUF_MAG)) >= 0
+ if (! (0 <= XINT (AREF (result, CCL_HEADER_BUF_MAG))
&& ASCENDING_ORDER (0, XINT (AREF (result, CCL_HEADER_EOF)),
ASIZE (ccl))))
return Qnil;
diff --git a/src/character.c b/src/character.c
index 5a06c7f4d6..b2caaa290a 100644
--- a/src/character.c
+++ b/src/character.c
@@ -833,8 +833,8 @@ string_escape_byte8 (Lisp_Object string)
if (multibyte)
{
- if (byte8_count > (MOST_POSITIVE_FIXNUM - nchars) / 3
- || byte8_count > (STRING_BYTES_BOUND - nbytes) / 2)
+ if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count
+ || (STRING_BYTES_BOUND - nbytes) / 2 < byte8_count)
string_overflow ();
/* Convert 2-byte sequence of byte8 chars to 4-byte octal. */
@@ -843,7 +843,7 @@ string_escape_byte8 (Lisp_Object string)
}
else
{
- if (byte8_count > (STRING_BYTES_BOUND - nbytes) / 3)
+ if ((STRING_BYTES_BOUND - nbytes) / 3 < byte8_count)
string_overflow ();
/* Convert 1-byte sequence of byte8 chars to 4-byte octal. */
diff --git a/src/charset.c b/src/charset.c
index 3d43d81877..fdb8eebde8 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -447,7 +447,7 @@ read_hex (FILE *fp, bool *eof, bool *overflow)
n = 0;
while (c_isxdigit (c = getc (fp)))
{
- if (n > UINT_MAX >> 4)
+ if (UINT_MAX >> 4 < n)
*overflow = 1;
n = ((n << 4)
| (c - ('0' <= c && c <= '9' ? '0'
diff --git a/src/data.c b/src/data.c
index b20d1b4c8a..6622088b64 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2337,13 +2337,13 @@ cons_to_unsigned (Lisp_Object c, uintmax_t max)
uintmax_t val IF_LINT (= 0);
if (INTEGERP (c))
{
- valid = XINT (c) >= 0;
+ valid = 0 <= XINT (c);
val = XINT (c);
}
else if (FLOATP (c))
{
double d = XFLOAT_DATA (c);
- if (d >= 0
+ if (0 <= d
&& d < (max == UINTMAX_MAX ? (double) UINTMAX_MAX + 1 : max + 1))
{
val = d;
diff --git a/src/dired.c b/src/dired.c
index ab48488966..7bbfee7e5b 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -517,8 +517,9 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
QUIT;
if (len < SCHARS (encoded_file)
- || scmp (dp->d_name, SSDATA (encoded_file),
- SCHARS (encoded_file)) >= 0)
+ || (scmp (dp->d_name, SSDATA (encoded_file),
+ SCHARS (encoded_file))
+ >= 0))
continue;
if (file_name_completion_stat (fd, dp, &st) < 0)
diff --git a/src/dispnew.c b/src/dispnew.c
index 836c0f9102..b4ca654a8f 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -4506,7 +4506,7 @@ update_frame_1 (struct frame *f, bool force_p, bool inhibit_id_p)
}
}
- lint_assume (FRAME_LINES (f) >= 0);
+ lint_assume (0 <= FRAME_LINES (f));
pause_p = 0 < i && i < FRAME_LINES (f) - 1;
/* Now just clean up termcap drivers and set cursor, etc. */
@@ -5772,7 +5772,7 @@ sit_for (Lisp_Object timeout, bool reading, int display_option)
else if (FLOATP (timeout))
{
double seconds = XFLOAT_DATA (timeout);
- if (seconds <= 0)
+ if (! (0 < seconds))
return Qt;
else
{
diff --git a/src/doc.c b/src/doc.c
index 1ddaa117bb..7234fb38bf 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -826,7 +826,7 @@ Otherwise, return a new string, without any text properties. */)
if (NILP (tem)) /* but not on any keys */
{
ptrdiff_t offset = bufp - buf;
- if (bsize > STRING_BYTES_BOUND - 4)
+ if (STRING_BYTES_BOUND - 4 < bsize)
string_overflow ();
buf = xrealloc (buf, bsize += 4);
bufp = buf + offset;
diff --git a/src/doprnt.c b/src/doprnt.c
index 087256ced2..471e35c7b4 100644
--- a/src/doprnt.c
+++ b/src/doprnt.c
@@ -361,7 +361,7 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
/* Copy string into final output, truncating if no room. */
doit:
- eassert (tem >= 0);
+ eassert (0 <= tem);
/* Coming here means STRING contains ASCII only. */
if (STRING_BYTES_BOUND < tem)
error ("Format width or precision too large");
diff --git a/src/editfns.c b/src/editfns.c
index d0cca6f3d7..e0b0347fe6 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1398,8 +1398,8 @@ hi_time (time_t t)
no runtime check is needed, and taking care not to convert
negative numbers to unsigned before comparing them. */
if (! ((! TYPE_SIGNED (time_t)
- || TIME_T_MIN >> 16 >= MOST_NEGATIVE_FIXNUM
- || hi >= MOST_NEGATIVE_FIXNUM)
+ || MOST_NEGATIVE_FIXNUM <= TIME_T_MIN >> 16
+ || MOST_NEGATIVE_FIXNUM <= hi)
&& (TIME_T_MAX >> 16 <= MOST_POSITIVE_FIXNUM
|| hi <= MOST_POSITIVE_FIXNUM)))
time_overflow ();
@@ -1561,7 +1561,7 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
if (result)
{
- if (hi >= (TYPE_SIGNED (time_t) ? TIME_T_MIN >> 16 : 0)
+ if ((TYPE_SIGNED (time_t) ? TIME_T_MIN >> 16 <= hi : 0 <= hi)
&& hi <= TIME_T_MAX >> 16)
{
/* Return the greatest representable time that is not greater
diff --git a/src/fileio.c b/src/fileio.c
index d7c476172c..2047338f03 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3449,7 +3449,7 @@ file_offset (Lisp_Object val)
if (FLOATP (val))
{
double v = XFLOAT_DATA (val);
- if (v >= 0
+ if (0 <= v
&& (sizeof (off_t) < sizeof v
? v <= TYPE_MAXIMUM (off_t)
: v < TYPE_MAXIMUM (off_t)))
diff --git a/src/fns.c b/src/fns.c
index 82ce933b25..b3a1dc2317 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3409,7 +3409,7 @@ larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max)
ptrdiff_t n_max = (0 <= nitems_max && nitems_max < C_language_max
? nitems_max : C_language_max);
eassert (VECTORP (vec));
- eassert (incr_min > 0 && nitems_max >= -1);
+ eassert (0 < incr_min && -1 <= nitems_max);
old_size = ASIZE (vec);
incr_max = n_max - old_size;
incr = max (incr_min, min (old_size >> 1, incr_max));
@@ -3574,9 +3574,9 @@ make_hash_table (struct hash_table_test test,
eassert (SYMBOLP (test.name));
eassert (INTEGERP (size) && XINT (size) >= 0);
eassert ((INTEGERP (rehash_size) && XINT (rehash_size) > 0)
- || (FLOATP (rehash_size) && XFLOAT_DATA (rehash_size) > 1));
+ || (FLOATP (rehash_size) && 1 < XFLOAT_DATA (rehash_size)));
eassert (FLOATP (rehash_threshold)
- && XFLOAT_DATA (rehash_threshold) > 0
+ && 0 < XFLOAT_DATA (rehash_threshold)
&& XFLOAT_DATA (rehash_threshold) <= 1.0);
if (XFASTINT (size) == 0)
@@ -4312,15 +4312,15 @@ usage: (make-hash-table &rest KEYWORD-ARGS) */)
/* Look for `:rehash-size SIZE'. */
i = get_key_arg (QCrehash_size, nargs, args, used);
rehash_size = i ? args[i] : make_float (DEFAULT_REHASH_SIZE);
- if (! ((INTEGERP (rehash_size) && XINT (rehash_size) > 0)
- || (FLOATP (rehash_size) && XFLOAT_DATA (rehash_size) > 1)))
+ if (! ((INTEGERP (rehash_size) && 0 < XINT (rehash_size))
+ || (FLOATP (rehash_size) && 1 < XFLOAT_DATA (rehash_size))))
signal_error ("Invalid hash table rehash size", rehash_size);
/* Look for `:rehash-threshold THRESHOLD'. */
i = get_key_arg (QCrehash_threshold, nargs, args, used);
rehash_threshold = i ? args[i] : make_float (DEFAULT_REHASH_THRESHOLD);
if (! (FLOATP (rehash_threshold)
- && XFLOAT_DATA (rehash_threshold) > 0
+ && 0 < XFLOAT_DATA (rehash_threshold)
&& XFLOAT_DATA (rehash_threshold) <= 1))
signal_error ("Invalid hash table rehash threshold", rehash_threshold);
diff --git a/src/font.c b/src/font.c
index d66620bffb..0b0144f319 100644
--- a/src/font.c
+++ b/src/font.c
@@ -229,7 +229,7 @@ font_intern_prop (const char *str, ptrdiff_t len, bool force_symbol)
if (len == 1 && *str == '*')
return Qnil;
- if (!force_symbol && len > 0 && '0' <= *str && *str <= '9')
+ if (!force_symbol && 0 < len && '0' <= *str && *str <= '9')
{
for (i = 1; i < len; i++)
if (! ('0' <= str[i] && str[i] <= '9'))
@@ -243,7 +243,7 @@ font_intern_prop (const char *str, ptrdiff_t len, bool force_symbol)
{
if (i == len)
return make_number (n);
- if (n > MOST_POSITIVE_FIXNUM / 10)
+ if (MOST_POSITIVE_FIXNUM / 10 < n)
break;
}
diff --git a/src/frame.c b/src/frame.c
index 970e40b517..0aeaf4cf41 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -889,7 +889,7 @@ DEFUN ("frame-list", Fframe_list, Sframe_list,
/* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
same tty (for tty frames) or among frames which uses FRAME's keyboard.
If MINIBUF is nil, do not consider minibuffer-only candidate.
- If MINIBUF is `visible', do not consider an invisible candidate.
+ If MINIBUF is `visible', do not consider an invisible candidate.
If MINIBUF is a window, consider only its own frame and candidate now
using that window as the minibuffer.
If MINIBUF is 0, consider candidate if it is visible or iconified.
@@ -3311,16 +3311,15 @@ x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
else if (FLOATP (item))
{
alpha = XFLOAT_DATA (item);
- if (alpha < 0.0 || alpha > 1.0)
+ if (! (0 <= alpha && alpha <= 1.0))
args_out_of_range (make_float (0.0), make_float (1.0));
}
else if (INTEGERP (item))
{
EMACS_INT ialpha = XINT (item);
- if (ialpha < 0 || ialpha > 100)
+ if (! (0 <= ialpha && alpha <= 100))
args_out_of_range (make_number (0), make_number (100));
- else
- alpha = ialpha / 100.0;
+ alpha = ialpha / 100.0;
}
else
wrong_type_argument (Qnumberp, item);
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 595a7427c2..f83d8660fc 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -543,7 +543,7 @@ get_utf8_string (const char *str)
if (cp) g_free (cp);
len = strlen (str);
- if (nr_bad > (min (PTRDIFF_MAX, SIZE_MAX) - len - 1) / 4)
+ if ((min (PTRDIFF_MAX, SIZE_MAX) - len - 1) / 4 < nr_bad)
memory_full (SIZE_MAX);
up = utf8_str = xmalloc (len + nr_bad * 4 + 1);
p = (unsigned char *)str;
diff --git a/src/indent.c b/src/indent.c
index 345dfaa9ce..67796ab8a8 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -466,7 +466,7 @@ check_display_width (ptrdiff_t pos, ptrdiff_t col, ptrdiff_t *endpos)
if ((prop = Fplist_get (plist, QCwidth),
RANGED_INTEGERP (0, prop, INT_MAX)))
width = XINT (prop);
- else if (FLOATP (prop) && XFLOAT_DATA (prop) >= 0
+ else if (FLOATP (prop) && 0 <= XFLOAT_DATA (prop)
&& XFLOAT_DATA (prop) <= INT_MAX)
width = (int)(XFLOAT_DATA (prop) + 0.5);
else if ((prop = Fplist_get (plist, QCalign_to),
diff --git a/src/keymap.c b/src/keymap.c
index e759214fa3..c43d528b25 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2063,7 +2063,7 @@ For an approximate inverse of this, see `kbd'. */)
size += XINT (Flength (prefix));
/* This has one extra element at the end that we don't pass to Fconcat. */
- if (size > min (PTRDIFF_MAX, SIZE_MAX) / word_size / 4)
+ if (min (PTRDIFF_MAX, SIZE_MAX) / word_size / 4 < size)
memory_full (SIZE_MAX);
SAFE_ALLOCA_LISP (args, size * 4);
diff --git a/src/lisp.h b/src/lisp.h
index 4481a2e337..82cf0cb267 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -543,7 +543,7 @@ static EMACS_INT const VALMASK
type or if I is a NaN. */
#define FIXNUM_OVERFLOW_P(i) \
- (! (((i) >= 0 || (i) >= MOST_NEGATIVE_FIXNUM) && (i) <= MOST_POSITIVE_FIXNUM))
+ (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM))
LISP_INLINE ptrdiff_t
clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
@@ -2560,7 +2560,7 @@ gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
LISP_INLINE void
vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count)
{
- eassert (offset >= 0 && count >= 0 && offset + count <= ASIZE (v));
+ eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v));
memcpy (XVECTOR (v)->contents + offset, args, count * sizeof *args);
}
diff --git a/src/lread.c b/src/lread.c
index d7a16f813c..8e623e838c 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -2636,7 +2636,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
nskip--;
else
UNREAD (c);
-
+
if (load_force_doc_strings
&& (FROM_FILE_P (readcharfun)))
{
@@ -2731,8 +2731,8 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
/* Read a non-negative integer. */
while (c >= '0' && c <= '9')
{
- if (n > MOST_POSITIVE_FIXNUM / 10
- || n * 10 + c - '0' > MOST_POSITIVE_FIXNUM)
+ if (MOST_POSITIVE_FIXNUM / 10 < n
+ || MOST_POSITIVE_FIXNUM < n * 10 + c - '0')
n = MOST_POSITIVE_FIXNUM + 1;
else
n = n * 10 + c - '0';
@@ -2930,7 +2930,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
if (end - p < MAX_MULTIBYTE_LENGTH)
{
ptrdiff_t offset = p - read_buffer;
- if (read_buffer_size > min (PTRDIFF_MAX, SIZE_MAX) / 2)
+ if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
memory_full (SIZE_MAX);
read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
read_buffer_size *= 2;
@@ -3064,7 +3064,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
if (end - p < MAX_MULTIBYTE_LENGTH)
{
ptrdiff_t offset = p - read_buffer;
- if (read_buffer_size > min (PTRDIFF_MAX, SIZE_MAX) / 2)
+ if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
memory_full (SIZE_MAX);
read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
read_buffer_size *= 2;
@@ -3094,7 +3094,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
if (p == end)
{
ptrdiff_t offset = p - read_buffer;
- if (read_buffer_size > min (PTRDIFF_MAX, SIZE_MAX) / 2)
+ if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
memory_full (SIZE_MAX);
read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
read_buffer_size *= 2;
diff --git a/src/minibuf.c b/src/minibuf.c
index 75e5478991..68c39310f0 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -251,7 +251,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
{
if (len == size)
{
- if (size > STRING_BYTES_BOUND / 2)
+ if (STRING_BYTES_BOUND / 2 < size)
memory_full (SIZE_MAX);
size *= 2;
line = xrealloc (line, size);
diff --git a/src/process.c b/src/process.c
index 6a14a53670..911a30bc80 100644
--- a/src/process.c
+++ b/src/process.c
@@ -4236,7 +4236,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
time_limit = 0;
nsecs = -1;
}
- else if (time_limit > TYPE_MAXIMUM (time_t))
+ else if (TYPE_MAXIMUM (time_t) < time_limit)
time_limit = TYPE_MAXIMUM (time_t);
/* Since we may need to wait several times,
diff --git a/src/search.c b/src/search.c
index ece346ecd0..ea36133deb 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2533,9 +2533,9 @@ since only regular expressions have distinguished subexpressions. */)
bool str_multibyte = STRING_MULTIBYTE (newtext);
bool really_changed = 0;
- substed_alloc_size = (length > (STRING_BYTES_BOUND - 100) / 2
- ? STRING_BYTES_BOUND
- : length * 2 + 100);
+ substed_alloc_size = (length <= (STRING_BYTES_BOUND - 100) / 2
+ ? length * 2 + 100
+ : STRING_BYTES_BOUND);
substed = xmalloc (substed_alloc_size);
substed_len = 0;
diff --git a/src/window.c b/src/window.c
index b66111a560..feb5f7b5cc 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5944,7 +5944,7 @@ get_phys_cursor_glyph (struct window *w)
hpos = row->used[TEXT_AREA] - 1;
}
- if (hpos >= 0 && hpos < row->used[TEXT_AREA])
+ if (0 <= hpos && hpos < row->used[TEXT_AREA])
glyph = row->glyphs[TEXT_AREA] + hpos;
else
glyph = NULL;
diff --git a/src/xdisp.c b/src/xdisp.c
index a7be5fc275..41214880a5 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -13168,7 +13168,7 @@ redisplay_internal (void)
PT == w->last_point
/* Make sure the cursor was last displayed
in this window. Otherwise we have to reposition it. */
- && w->cursor.vpos >= 0
+ && 0 <= w->cursor.vpos
&& w->cursor.vpos < WINDOW_TOTAL_LINES (w))
{
if (!must_finish)
diff --git a/src/xsmfns.c b/src/xsmfns.c
index 0af196d216..cb7122202d 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -221,7 +221,7 @@ smc_save_yourself_CB (SmcConn smcConn,
props[props_idx]->name = xstrdup (SmRestartCommand);
props[props_idx]->type = xstrdup (SmLISTofARRAY8);
/* /path/to/emacs, --smid=xxx --no-splash --chdir=dir ... */
- if (initial_argc > INT_MAX - 3)
+ if (INT_MAX - 3 < initial_argc)
memory_full (SIZE_MAX);
i = 3 + initial_argc;
props[props_idx]->num_vals = i;