]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix unlikely time zone abbreviation bug
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 27 Jan 2025 06:15:48 +0000 (22:15 -0800)
committerEshel Yaron <me@eshelyaron.com>
Thu, 30 Jan 2025 18:06:15 +0000 (19:06 +0100)
* src/timefns.c (Fcurrent_time_zone): Fix double-"-" bug when time
zone name is not known and time zone offset is -3600 or less.
Also, stop assuming that make_formatted_string works with "*"
precisions; this might ease future changes.

(cherry picked from commit bcfd4d21b0a62c5c15b919fa28673066c493775a)

src/timefns.c

index 4fb142f2f1bcdc4caa5adfc0d381e46659518c5f..590d84c4d656c95cbbd3d9d7e20ad331eb6b18df 100644 (file)
@@ -1950,15 +1950,24 @@ the data it can't find.  */)
          /* No local time zone name is available; use numeric zone instead.  */
          long int hour = offset / 3600;
          int min_sec = offset % 3600;
-         int amin_sec = eabs (min_sec);
-         int min = amin_sec / 60;
-         int sec = amin_sec % 60;
-         int min_prec = min_sec ? 2 : 0;
-         int sec_prec = sec ? 2 : 0;
-         char buf[sizeof "+0000" + INT_STRLEN_BOUND (long int)];
-         zone_name = make_formatted_string (buf, "%c%.2ld%.*d%.*d",
-                                            (offset < 0 ? '-' : '+'),
-                                            hour, min_prec, min, sec_prec, sec);
+         char buf[INT_STRLEN_BOUND (long int) + sizeof "5959"];
+         int buflen = 0;
+         buf[buflen++] = offset < 0 ? '-' : '+';
+         buflen += sprintf (buf + buflen, "%.2ld", eabs (hour));
+         if (min_sec)
+           {
+             int amin_sec = eabs (min_sec);
+             int min = amin_sec / 60;
+             int sec = amin_sec % 60;
+             buf[buflen++] = '0' + min / 10;
+             buf[buflen++] = '0' + min % 10;
+             if (sec)
+               {
+                 buf[buflen++] = '0' + sec / 10;
+                 buf[buflen++] = '0' + sec % 10;
+               }
+           }
+         zone_name = make_string (buf, buflen);
        }
     }