Commit 7216e43b authored by Paul Eggert's avatar Paul Eggert

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.
parent 4b725a70
2013-04-02 Paul Eggert <eggert@cs.ucla.edu>
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 <dmantipov@yandex.ru>
* frame.h (struct frame): Drop scroll_bottom_vpos
......
......@@ -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;
......
......@@ -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;
......
......@@ -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. */
......
......@@ -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'
......
......@@ -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;
......
......@@ -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)
......
......@@ -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
{
......
......@@ -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;
......
......@@ -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");
......
......@@ -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
......
......@@ -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)))
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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;
......
......@@ -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),
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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);
......
......@@ -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,
......
......@@ -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;
......
......@@ -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;
......
......@@ -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)
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment