1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-22 07:09:54 +00:00

Pacify GCC 12 in default developer build

This lets ‘./configure; make’ work on Fedora 36 x86-64 from a Git
checkout without generating false-alarm warnings.
* lib-src/etags.c (main): There appeared to be false alarm with
GCC 12.  However, the code was wrong anyway, as it mishandled file
names containing "'" so fix that bug.  This pacifies GCC.
(mercury_decl): Omit tests ‘s + pos != NULL’ that were apparently
intended to be ‘s[pos] != '\0'’ but which were miscoded to always
be true and which were mostly not needed anyway.  In one place,
though, a test was needed, so fix that by using strchr instead.
* src/alloc.c (lisp_free) [!GC_MALLOC_CHECK]:
* src/term.c (Fsuspend_tty): Don’t look at a pointer after freeing
it, even just to test it for equality with some other pointer, as
this has undefined behavior in C and GCC 12 diagnoses this.
* src/dbusbind.c (xd_read_message_1): Rework the code a bit
so that it has fewer tests.  This pacifies GCC 12 which was
complaining incorrectly about dereferencing a null pointer.
* src/intervals.c (copy_properties): Remove an eassume that should
no longer be needed even to pacify older GCCs, due to ...
* src/intervals.h (split_interval_left): ... this addition of
ATTRIBUTE_RETURNS_NONNULL to pacify a GCC 12 warning about
dereferencing a null pointer.
* src/regex-emacs.c (EXTEND_BUFFER): Use negative values rather
than auxiliary booleans to indicate null pointers.  This pacifies
GCC 12 false alarms about using uninitialized variables.
* src/xdisp.c (clear_position): New function.
(append_space_for_newline, extend_face_to_end_of_line):
Use it to work around false alarms from GCC 12.
(display_and_set_cursor): Add an UNINIT to pacify GCC 12.
* src/xterm.c (x_draw_glyphless_glyph_string_foreground):
Defend against hypothetical bad code elsewhere;
this also pacifies GCC 12.
(x_term_init): Use fixed-size auto array rather than alloca,
as the array is small; this also pacifies GCC 12.
This commit is contained in:
Paul Eggert 2022-05-12 17:01:10 -07:00
parent 454caf858d
commit 0f731c49e6
9 changed files with 78 additions and 63 deletions

View File

@ -1427,14 +1427,19 @@ main (int argc, char **argv)
if (CTAGS)
if (append_to_tagfile || update)
{
char *cmd = xmalloc (2 * strlen (tagfile) + sizeof "sort -u -o..");
/* Maybe these should be used:
setenv ("LC_COLLATE", "C", 1);
setenv ("LC_ALL", "C", 1); */
char *z = stpcpy (cmd, "sort -u -o ");
z = stpcpy (z, tagfile);
*z++ = ' ';
strcpy (z, tagfile);
char *cmd = xmalloc (8 * strlen (tagfile) + sizeof "sort -u -o '' ''");
char *z = stpcpy (cmd, "sort -u -o '");
char *escaped_tagfile = z;
for (; *tagfile; *z++ = *tagfile++)
if (*tagfile == '\'')
z = stpcpy (z, "'\\'");
ptrdiff_t escaped_tagfile_len = z - escaped_tagfile;
z = stpcpy (z, "' '");
z = mempcpy (z, escaped_tagfile, escaped_tagfile_len);
strcpy (z, "'");
return system (cmd);
}
return EXIT_SUCCESS;
@ -6396,7 +6401,8 @@ mercury_decl (char *s, size_t pos)
size_t origpos;
origpos = pos;
while (s + pos != NULL && (c_isalnum (s[pos]) || s[pos] == '_')) ++pos;
while (c_isalnum (s[pos]) || s[pos] == '_')
pos++;
unsigned char decl_type_length = pos - origpos;
char buf[decl_type_length + 1];
@ -6440,9 +6446,9 @@ mercury_decl (char *s, size_t pos)
so this is the hard case. */
if (strcmp (buf, "solver") == 0)
{
++pos;
while (s + pos != NULL && (c_isalnum (s[pos]) || s[pos] == '_'))
++pos;
do
pos++;
while (c_isalnum (s[pos]) || s[pos] == '_');
decl_type_length = pos - origpos;
char buf2[decl_type_length + 1];
@ -6492,7 +6498,6 @@ mercury_decl (char *s, size_t pos)
while (c_isalnum (s[pos])
|| s[pos] == '_'
|| (s[pos] == '.' /* A module dot. */
&& s + pos + 1 != NULL
&& (c_isalnum (s[pos + 1]) || s[pos + 1] == '_')
&& (module_dot_pos = pos))) /* Record module dot position.
Erase module from name. */
@ -6536,10 +6541,10 @@ mercury_decl (char *s, size_t pos)
}
else if (is_mercury_quantifier && s[pos] == '[') /* :- some [T] pred/func. */
{
for (++pos; s + pos != NULL && s[pos] != ']'; ++pos) {}
if (s + pos == NULL) return null_pos;
++pos;
pos = skip_spaces (s + pos) - s;
char *close_bracket = strchr (s + pos + 1, ']');
if (!close_bracket)
return null_pos;
pos = skip_spaces (close_bracket + 1) - s;
mercury_pos_t position = mercury_decl (s, pos);
position.totlength += pos - origpos;
return position;

View File

@ -1032,9 +1032,12 @@ lisp_free (void *block)
return;
MALLOC_BLOCK_INPUT;
#ifndef GC_MALLOC_CHECK
struct mem_node *m = mem_find (block);
#endif
free (block);
#ifndef GC_MALLOC_CHECK
mem_delete (mem_find (block));
mem_delete (m);
#endif
MALLOC_UNBLOCK_INPUT;
}

View File

@ -1690,29 +1690,30 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
value = Fgethash (key, Vdbus_registered_objects_table, Qnil);
/* Loop over the registered functions. Construct an event. */
while (!NILP (value))
for (; !NILP (value); value = CDR_SAFE (value))
{
key = CAR_SAFE (value);
Lisp_Object key_uname = CAR_SAFE (key);
/* key has the structure (UNAME SERVICE PATH HANDLER). */
if (((uname == NULL)
|| (NILP (CAR_SAFE (key)))
|| (strcmp (uname, SSDATA (CAR_SAFE (key))) == 0))
&& ((path == NULL)
|| (NILP (CAR_SAFE (CDR_SAFE (CDR_SAFE (key)))))
|| (strcmp (path,
SSDATA (CAR_SAFE (CDR_SAFE (CDR_SAFE (key)))))
== 0))
&& (!NILP (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (key)))))))
{
EVENT_INIT (event);
event.kind = DBUS_EVENT;
event.frame_or_window = Qnil;
/* Handler. */
event.arg
= Fcons (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (key)))), args);
break;
}
value = CDR_SAFE (value);
if (uname && !NILP (key_uname)
&& strcmp (uname, SSDATA (key_uname)) != 0)
continue;
Lisp_Object key_service_etc = CDR_SAFE (key);
Lisp_Object key_path_etc = CDR_SAFE (key_service_etc);
Lisp_Object key_path = CAR_SAFE (key_path_etc);
if (path && !NILP (key_path)
&& strcmp (path, SSDATA (key_path)) != 0)
continue;
Lisp_Object handler = CAR_SAFE (CDR_SAFE (key_path_etc));
if (NILP (handler))
continue;
/* Construct an event and exit the loop. */
EVENT_INIT (event);
event.kind = DBUS_EVENT;
event.frame_or_window = Qnil;
event.arg = Fcons (handler, args);
break;
}
if (NILP (value))

View File

@ -121,7 +121,6 @@ copy_properties (INTERVAL source, INTERVAL target)
{
if (DEFAULT_INTERVAL_P (source) && DEFAULT_INTERVAL_P (target))
return;
eassume (source && target);
COPY_INTERVAL_CACHE (source, target);
set_interval_plist (target, Fcopy_sequence (source->plist));

View File

@ -251,7 +251,7 @@ extern void traverse_intervals_noorder (INTERVAL,
void (*) (INTERVAL, void *), void *);
extern INTERVAL split_interval_right (INTERVAL, ptrdiff_t)
ATTRIBUTE_RETURNS_NONNULL;
extern INTERVAL split_interval_left (INTERVAL, ptrdiff_t);
extern INTERVAL split_interval_left (INTERVAL, ptrdiff_t) ATTRIBUTE_RETURNS_NONNULL;
extern INTERVAL find_interval (INTERVAL, ptrdiff_t);
extern INTERVAL next_interval (INTERVAL);
extern INTERVAL previous_interval (INTERVAL);

View File

@ -1244,21 +1244,22 @@ static int analyze_first (re_char *p, re_char *pend,
return REG_ESIZE; \
ptrdiff_t b_off = b - old_buffer; \
ptrdiff_t begalt_off = begalt - old_buffer; \
bool fixup_alt_jump_set = !!fixup_alt_jump; \
bool laststart_set = !!laststart; \
bool pending_exact_set = !!pending_exact; \
ptrdiff_t fixup_alt_jump_off, laststart_off, pending_exact_off; \
if (fixup_alt_jump_set) fixup_alt_jump_off = fixup_alt_jump - old_buffer; \
if (laststart_set) laststart_off = laststart - old_buffer; \
if (pending_exact_set) pending_exact_off = pending_exact - old_buffer; \
ptrdiff_t fixup_alt_jump_off = \
fixup_alt_jump ? fixup_alt_jump - old_buffer : -1; \
ptrdiff_t laststart_off = laststart ? laststart - old_buffer : -1; \
ptrdiff_t pending_exact_off = \
pending_exact ? pending_exact - old_buffer : -1; \
bufp->buffer = xpalloc (bufp->buffer, &bufp->allocated, \
requested_extension, MAX_BUF_SIZE, 1); \
unsigned char *new_buffer = bufp->buffer; \
b = new_buffer + b_off; \
begalt = new_buffer + begalt_off; \
if (fixup_alt_jump_set) fixup_alt_jump = new_buffer + fixup_alt_jump_off; \
if (laststart_set) laststart = new_buffer + laststart_off; \
if (pending_exact_set) pending_exact = new_buffer + pending_exact_off; \
if (0 <= fixup_alt_jump_off) \
fixup_alt_jump = new_buffer + fixup_alt_jump_off; \
if (0 <= laststart_off) \
laststart = new_buffer + laststart_off; \
if (0 <= pending_exact_off) \
pending_exact = new_buffer + pending_exact_off; \
} while (false)

View File

@ -2287,9 +2287,9 @@ A suspended tty may be resumed by calling `resume-tty' on it. */)
delete_keyboard_wait_descriptor (fileno (f));
#ifndef MSDOS
fclose (f);
if (f != t->display_info.tty->output)
fclose (t->display_info.tty->output);
fclose (f);
#endif
t->display_info.tty->input = 0;

View File

@ -22471,6 +22471,13 @@ compute_line_metrics (struct it *it)
}
static void
clear_position (struct it *it)
{
it->position.charpos = 0;
it->position.bytepos = 0;
}
/* Append one space to the glyph row of iterator IT if doing a
window-based redisplay. The space has the same face as
IT->face_id. Value is true if a space was added.
@ -22506,7 +22513,7 @@ append_space_for_newline (struct it *it, bool default_face_p)
struct face *face;
it->what = IT_CHARACTER;
memset (&it->position, 0, sizeof it->position);
clear_position (it);
it->object = Qnil;
it->len = 1;
@ -22835,7 +22842,7 @@ extend_face_to_end_of_line (struct it *it)
const int stretch_width =
indicator_column - it->current_x - char_width;
memset (&it->position, 0, sizeof it->position);
clear_position (it);
/* Only generate a stretch glyph if there is distance
between current_x and the indicator position. */
@ -22869,7 +22876,7 @@ extend_face_to_end_of_line (struct it *it)
if (stretch_width > 0)
{
memset (&it->position, 0, sizeof it->position);
clear_position (it);
append_stretch_glyph (it, Qnil, stretch_width,
it->ascent + it->descent,
stretch_ascent);
@ -22919,7 +22926,7 @@ extend_face_to_end_of_line (struct it *it)
(((it->ascent + it->descent)
* FONT_BASE (font)) / FONT_HEIGHT (font));
saved_pos = it->position;
memset (&it->position, 0, sizeof it->position);
clear_position (it);
saved_avoid_cursor = it->avoid_cursor_p;
it->avoid_cursor_p = true;
saved_face_id = it->face_id;
@ -22957,7 +22964,7 @@ extend_face_to_end_of_line (struct it *it)
enum display_element_type saved_what = it->what;
it->what = IT_CHARACTER;
memset (&it->position, 0, sizeof it->position);
clear_position (it);
it->object = Qnil;
it->c = it->char_to_display = ' ';
it->len = 1;
@ -32651,7 +32658,7 @@ display_and_set_cursor (struct window *w, bool on,
{
struct frame *f = XFRAME (w->frame);
int new_cursor_type;
int new_cursor_width;
int new_cursor_width UNINIT;
bool active_cursor;
struct glyph_row *glyph_row;
struct glyph *glyph;

View File

@ -6621,6 +6621,10 @@ x_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
glyph->ascent + glyph->descent - 1);
x += glyph->pixel_width;
}
/* Defend against hypothetical bad code elsewhere that uses
s->char2b after this function returns. */
s->char2b = NULL;
}
#ifdef USE_X_TOOLKIT
@ -23521,7 +23525,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
#ifdef USE_XCB
xcb_connection_t *xcb_conn;
#endif
char *cm_atom_sprintf;
static char const cm_atom_fmt[] = "_NET_WM_CM_S%d";
char cm_atom_sprintf[sizeof cm_atom_fmt - 2 + INT_STRLEN_BOUND (int)];
block_input ();
@ -24212,14 +24217,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
dpyinfo->resx = (mm < 1) ? 100 : pixels * 25.4 / mm;
}
{
int n = snprintf (NULL, 0, "_NET_WM_CM_S%d",
XScreenNumberOfScreen (dpyinfo->screen));
cm_atom_sprintf = alloca (n + 1);
snprintf (cm_atom_sprintf, n + 1, "_NET_WM_CM_S%d",
XScreenNumberOfScreen (dpyinfo->screen));
}
sprintf (cm_atom_sprintf, cm_atom_fmt,
XScreenNumberOfScreen (dpyinfo->screen));
{
static const struct