From 2e8cc206f520ec9feb42273703d7afbcb32cd791 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 21 Mar 2023 14:06:27 -0700 Subject: Avoid backwards clock in movemail timestamps * lib-src/movemail.c (mbx_delimit_begin): Use ‘current_timespec’ instead of ‘time’ to generate the user-visible timestamp. This works around the minor glitch caused by glibc bug 30200 . --- lib-src/movemail.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib-src') diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 8119046a916..972ab7156fa 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c @@ -846,7 +846,7 @@ movemail_strftime (char *s, size_t size, char const *format, static bool mbx_delimit_begin (FILE *mbf) { - time_t now = time (NULL); + time_t now = current_timespec ().tv_sec; struct tm *ltime = localtime (&now); if (!ltime) return false; -- cgit v1.2.1 From 640fd9b594fa376e6493efbe0cf083e1270ddd3f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 21 Mar 2023 14:38:23 -0700 Subject: Sleep less in update-game-score This is mostly to avoid interface hassles with time/srand/rand. * lib-src/update-game-score.c (main): Don’t use ‘srand’ or ‘time’. (lock_file): Don’t sleep if we unlocked the lock file. When sleeping, always just sleep 1 s. This avoids the need for calling ‘time’ and ‘rand’, the utility of which was dubious anyway. --- lib-src/update-game-score.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib-src') diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index 83167f59b8a..4592e14d1d6 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c @@ -185,8 +185,6 @@ main (int argc, char **argv) ptrdiff_t scorecount, scorealloc; ptrdiff_t max_scores = MAX_SCORES; - srand (time (0)); - while ((c = getopt (argc, argv, "hrm:d:")) != -1) switch (c) { @@ -485,8 +483,8 @@ lock_file (const char *filename, void **state) return -1; attempts = 0; } - - sleep ((rand () & 1) + 1); + else + sleep (1); } close (fd); -- cgit v1.2.1 From e340354299421a1a0773e6443f7901964b5d7c6d Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 22 Mar 2023 17:26:22 +0200 Subject: Fix compilation of lib-src/movemail * lib-src/movemail.c: Include timespec.h. Reported by Andreas Schwab . --- lib-src/movemail.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib-src') diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 972ab7156fa..a71be8c2099 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c @@ -62,6 +62,7 @@ along with GNU Emacs. If not, see . */ #include #include #include +#include #include #include -- cgit v1.2.1 From 3e3f34d71e9c3c6c943580dc822afed7a3b0a861 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 14 May 2023 18:51:22 -0700 Subject: Fix ebrowse -f buffer overflow * lib-src/ebrowse.c (main): Fix buffer overflow when several -f options are given. Found by GCC 13 -Wanalyzer-allocation-size. --- lib-src/ebrowse.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib-src') diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c index 371fa6c938b..4b71f7447e0 100644 --- a/lib-src/ebrowse.c +++ b/lib-src/ebrowse.c @@ -3767,8 +3767,9 @@ main (int argc, char **argv) if (n_input_files == input_filenames_size) { input_filenames_size = max (10, 2 * input_filenames_size); - input_filenames = (char **) xrealloc ((void *)input_filenames, - input_filenames_size); + input_filenames = xrealloc (input_filenames, + (input_filenames_size + * sizeof *input_filenames)); } input_filenames[n_input_files++] = xstrdup (optarg); break; -- cgit v1.2.1 From 92d4bda27976b381fc1f7905e83bdb9da050261e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 14 May 2023 18:51:22 -0700 Subject: Fix movemail fd leak * lib-src/movemail.c (main) [!MAIL_USE_SYSTEM_LOCK]: Fix file descriptor leak, found by GCC 13 -Wanalyzer-fd-leak. --- lib-src/movemail.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib-src') diff --git a/lib-src/movemail.c b/lib-src/movemail.c index a71be8c2099..6a772e9043e 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c @@ -470,7 +470,7 @@ main (int argc, char **argv) that were set on the file. Better to just empty the file. */ if (unlink (inname) < 0 && errno != ENOENT) #endif /* MAIL_UNLINK_SPOOL */ - creat (inname, 0600); + close (creat (inname, 0600)); } #endif /* not MAIL_USE_SYSTEM_LOCK */ -- cgit v1.2.1 From 5ef169ed701fa4f850fdca5563cdd468207d5d4f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 17 May 2023 15:36:54 -0700 Subject: Prefer C23 ckd_* to Gnulib *_WRAPV macros C23 has added ckd_add etc. macros with functionality equivalent to the older Gnulib INT_ADD_WRAPV macros, so switch to the more-standard names. * admin/merge-gnulib (GNULIB_MODULES): Add stdckdint. This merely makes the dependency explicit, as we were already using this Gnulib module indirectly. * lib-src/etags.c, src/lisp.h: Include stdckdint.h. * lib-src/etags.c (xnmalloc, xnrealloc): * src/alloc.c (xnmalloc, xnrealloc, xpalloc, Fmake_string) (mark_memory): * src/bignum.c (emacs_mpz_pow_ui): * src/buffer.c (record_overlay_string, overlay_strings): * src/bytecode.c (exec_byte_code): * src/casefiddle.c (do_casify_multibyte_string): * src/ccl.c (ccl_driver, Fccl_execute_on_string): * src/character.c (char_width, c_string_width) (lisp_string_width, count_size_as_multibyte) (string_escape_byte8): * src/cmds.c (internal_self_insert): * src/coding.c (coding_alloc_by_realloc, produce_chars): * src/data.c (arith_driver): * src/dispnew.c (realloc_glyph_pool, init_display_interactive): * src/doprnt.c (parse_format_integer): * src/editfns.c (Freplace_buffer_contents, str2num) (styled_format): * src/emacs-module.c (module_global_reference_p) (module_make_global_ref, module_funcall): * src/eval.c (max_ensure_room): * src/fileio.c (blocks_to_bytes): * src/fns.c (Ffillarray): * src/font.c (font_intern_prop): * src/frame.c (check_frame_pixels): * src/gnutls.c (gnutls_hex_string, gnutls_symmetric_aead): * src/gtkutil.c (get_utf8_string): * src/haikuterm.c (haiku_term_init): * src/image.c (xbm_scan, image_to_emacs_colors) (image_detect_edges, png_load_body): * src/keyboard.c (Frecursion_depth): * src/keymap.c (Flookup_key, Fkey_description): * src/lisp.h (modiff_incr, SAFE_ALLOCA_LISP_EXTRA): * src/lread.c (read_bool_vector): * src/pgtkterm.c (pgtk_term_init): * src/regex-emacs.c (regex_compile): * src/term.c (encode_terminal_code): * src/termcap.c (tputs): * src/textconv.c (textconv_query): * src/timefns.c (timespec_ticks, lisp_time_hz_ticks) (Fdecode_time, check_tm_member): * src/tparam.c (tparam1): * src/w32term.c (w32_initialize_display_info): * src/xdisp.c (fill_column_indicator_column, decode_mode_spec): * src/xselect.c (selection_data_size, x_property_data_to_lisp): * src/xsmfns.c (smc_save_yourself_CB): * src/xterm.c (xm_setup_dnd_targets, x_sync_get_monotonic_time) (x_sync_current_monotonic_time, x_sync_note_frame_times) (x_display_set_last_user_time, x_term_init): Prefer the C23 stdckdint macros to their Gnulib intprops.h counterparts, since C23 is standard. --- lib-src/etags.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib-src') diff --git a/lib-src/etags.c b/lib-src/etags.c index 2c6b4e7a630..147ecbd7c1b 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -109,6 +109,7 @@ University of California, as described above. */ #include #include #include +#include #include #include #include @@ -8038,7 +8039,7 @@ xnmalloc (ptrdiff_t nitems, ptrdiff_t item_size) ptrdiff_t nbytes; assume (0 <= nitems); assume (0 < item_size); - if (INT_MULTIPLY_WRAPV (nitems, item_size, &nbytes)) + if (ckd_mul (&nbytes, nitems, item_size)) memory_full (); return xmalloc (nbytes); } @@ -8049,7 +8050,7 @@ xnrealloc (void *pa, ptrdiff_t nitems, ptrdiff_t item_size) ptrdiff_t nbytes; assume (0 <= nitems); assume (0 < item_size); - if (INT_MULTIPLY_WRAPV (nitems, item_size, &nbytes) || SIZE_MAX < nbytes) + if (ckd_mul (&nbytes, nitems, item_size) || SIZE_MAX < nbytes) memory_full (); void *result = realloc (pa, nbytes); if (!result) -- cgit v1.2.1