public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix l64a description in glibc manual [BZ #266]
@ 2004-07-14 11:33 Jakub Jelinek
  2004-07-14 17:33 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2004-07-14 11:33 UTC (permalink / raw)
  To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers

Hi!

2004-07-14  Jakub Jelinek  <jakub@redhat.com>

	[BZ #266]
	* manual/string.texi (l64a): Note that the static buffer is 7 bytes
	long.  Rewrite example code so that it takes account l64a output
	shorter than 6 characters.
	Reported by Julian Graham <julian.graham@aya.yale.edu>.

--- libc/manual/string.texi.jj	2004-05-25 18:35:42.000000000 +0200
+++ libc/manual/string.texi	2004-07-14 13:30:21.102893652 +0200
@@ -2296,7 +2296,7 @@ this task.
 @comment XPG
 @deftypefun {char *} l64a (long int @var{n})
 This function encodes a 32-bit input value using characters from the
-basic character set.  It returns a pointer to a 6 character buffer which
+basic character set.  It returns a pointer to a 7 character buffer which
 contains an encoded version of @var{n}.  To encode a series of bytes the
 user must copy the returned string to a destination buffer.  It returns
 the empty string if @var{n} is zero, which is somewhat bizarre but
@@ -2321,13 +2321,17 @@ encode (const void *buf, size_t len)
   /* @r{We know in advance how long the buffer has to be.} */
   unsigned char *in = (unsigned char *) buf;
   char *out = malloc (6 + ((len + 3) / 4) * 6 + 1);
-  char *cp = out;
+  char *cp = out, *p;
 
   /* @r{Encode the length.} */
   /* @r{Using `htonl' is necessary so that the data can be}
-     @r{decoded even on machines with different byte order.} */
+     @r{decoded even on machines with different byte order.}
+     @r{`l64a' can return a string shorter than 6 bytes, so }
+     @r{we pad it with encoding of 0 (}'.'@r{) at the end by }
+     @r{hand.} */
 
-  cp = mempcpy (cp, l64a (htonl (len)), 6);
+  p = stpcpy (cp, l64a (htonl (len)));
+  cp = mempcpy (p, "......", 6 - (p - cp));
 
   while (len > 3)
     @{
@@ -2336,12 +2340,8 @@ encode (const void *buf, size_t len)
       n = (n << 8) | *in++;
       n = (n << 8) | *in++;
       len -= 4;
-      if (n)
-        cp = mempcpy (cp, l64a (htonl (n)), 6);
-      else
-            /* @r{`l64a' returns the empty string for n==0, so we }
-               @r{must generate its encoding (}"......"@r{) by hand.} */
-        cp = stpcpy (cp, "......");
+      p = stpcpy (cp, l64a (htonl (n)));
+      cp = mempcpy (p, "......", 6 - (p - cp));
     @}
   if (len > 0)
     @{
@@ -2352,8 +2352,7 @@ encode (const void *buf, size_t len)
           if (--len > 0)
             n = (n << 8) | *in;
         @}
-      memcpy (cp, l64a (htonl (n)), 6);
-      cp += 6;
+      cp = stpcpy (cp, l64a (htonl (n)));
     @}
   *cp = '\0';
   return out;

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix l64a description in glibc manual [BZ #266]
  2004-07-14 11:33 [PATCH] Fix l64a description in glibc manual [BZ #266] Jakub Jelinek
@ 2004-07-14 17:33 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2004-07-14 17:33 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

Applied.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-07-14 17:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-14 11:33 [PATCH] Fix l64a description in glibc manual [BZ #266] Jakub Jelinek
2004-07-14 17:33 ` Ulrich Drepper

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).