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-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
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)
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;
}
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)))
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;
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. */
}
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. */
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'
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;
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)
}
}
- 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. */
else if (FLOATP (timeout))
{
double seconds = XFLOAT_DATA (timeout);
- if (seconds <= 0)
+ if (! (0 < seconds))
return Qt;
else
{
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;
/* 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");
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 ();
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
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)))
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));
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)
/* 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);
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'))
{
if (i == len)
return make_number (n);
- if (n > MOST_POSITIVE_FIXNUM / 10)
+ if (MOST_POSITIVE_FIXNUM / 10 < n)
break;
}
/* 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.
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);
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;
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),
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);
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)
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);
}
nskip--;
else
UNREAD (c);
-
+
if (load_force_doc_strings
&& (FROM_FILE_P (readcharfun)))
{
/* 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';
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;
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;
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;
{
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);
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,
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;
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;
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)
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;