public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix localedef (era info in LC_TIME)
@ 2003-06-12 17:07 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2003-06-12 17:07 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

2003-04-16 ld-time.c broke LC_TIME era data. strncpy cannot be used, since
we usually need to copy 2 strings and then pad with zeros instead of one
string plus zero padding. One string is there only in case of
failure, where name = format = "". In this case, we copy just one string
("") and pad to 4 bytes, so that we get the needed "\0" followed by padding.

2003-06-12  Jakub Jelinek  <jakub@redhat.com>

	* locale/programs/ld-time.c (time_output): Don't overwrite era_format
	with zeros.

--- libc/locale/programs/ld-time.c.jj	2003-04-23 14:11:51.000000000 -0400
+++ libc/locale/programs/ld-time.c	2003-06-12 12:41:51.000000000 -0400
@@ -670,7 +670,7 @@ time_output (struct localedef_t *locale,
   idx[1 + last_idx] = idx[last_idx];
   for (num = 0; num < time->num_era; ++num)
     {
-      size_t l;
+      size_t l, l2;
 
       iov[2 + cnt].iov_base = (void *) &time->era_entries[num].direction;
       iov[2 + cnt].iov_len = sizeof (int32_t);
@@ -699,15 +699,14 @@ time_output (struct localedef_t *locale,
 
       l = ((char *) rawmemchr (time->era_entries[num].format, '\0')
 	   - time->era_entries[num].name) + 1;
-      l = (l + 3) & ~3;
-      iov[2 + cnt].iov_base = alloca (l);
-      /* This time we *really* want to use the properties of strncpy.  */
-      strncpy (iov[2 + cnt].iov_base, time->era_entries[num].name,
-	       l);
-      iov[2 + cnt].iov_len = l;
+      l2 = (l + 3) & ~3;
+      iov[2 + cnt].iov_base = alloca (l2);
+      memset (mempcpy (iov[2 + cnt].iov_base, time->era_entries[num].name, l),
+	      '\0', l2 - l);
+      iov[2 + cnt].iov_len = l2;
       ++cnt;
 
-      idx[1 + last_idx] += 8 * sizeof (int32_t) + l;
+      idx[1 + last_idx] += 8 * sizeof (int32_t) + l2;
 
       assert (idx[1 + last_idx] % 4 == 0);
 

	Jakub

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-06-12 17:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-12 17:07 [PATCH] Fix localedef (era info in LC_TIME) Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).