Remove nested functions: crypt/md5-crypt.c
authorKonstantin Serebryany <konstantin.s.serebryany@gmail.com>
Thu, 22 May 2014 02:59:00 +0000 (08:29 +0530)
committerSiddhesh Poyarekar <siddhesh@redhat.com>
Thu, 22 May 2014 14:56:19 +0000 (20:26 +0530)
This patch is the first in the series of patches that remove nested
functions from glibc.
Rationale: nested functions is a non-standard language feature;
removing nested functions
will allow to compile glibc with compilers other than GCC and thus
benefit from other compilers
and code analysis tools.

ChangeLog
crypt/md5-crypt.c

index 77fed0c..771f3c5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-05-22  Kostya Serebryany  <konstantin.s.serebryany@gmail.com>
+
+       * crypt/md5-crypt.c (__md5_crypt_r): Remove a nested function.
+       (b64_from_24bit): New function.
+
 2014-05-22  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>
 
        * sysdeps/powerpc/powerpc32/power4/multiarch/memchr.c (memchr): Remove
index d1b92d7..5d5fc55 100644 (file)
@@ -88,6 +88,20 @@ extern char *__md5_crypt_r (const char *key, const char *salt,
                            char *buffer, int buflen);
 extern char *__md5_crypt (const char *key, const char *salt);
 
+static void
+b64_from_24bit (char **cp, int *buflen,
+                unsigned int b2, unsigned int b1, unsigned int b0,
+                int n)
+{
+  unsigned int w = (b2 << 16) | (b1 << 8) | b0;
+  while (n-- > 0 && *buflen > 0)
+    {
+      *(*cp)++ = b64t[w & 0x3f];
+      --*buflen;
+      w >>= 6;
+    }
+}
+
 
 /* This entry point is equivalent to the `crypt' function in Unix
    libcs.  */
@@ -268,24 +282,18 @@ __md5_crypt_r (key, salt, buffer, buflen)
       --buflen;
     }
 
-  void b64_from_24bit (unsigned int b2, unsigned int b1, unsigned int b0,
-                      int n)
-  {
-    unsigned int w = (b2 << 16) | (b1 << 8) | b0;
-    while (n-- > 0 && buflen > 0)
-      {
-       *cp++ = b64t[w & 0x3f];
-       --buflen;
-       w >>= 6;
-      }
-  }
-
-  b64_from_24bit (alt_result[0], alt_result[6], alt_result[12], 4);
-  b64_from_24bit (alt_result[1], alt_result[7], alt_result[13], 4);
-  b64_from_24bit (alt_result[2], alt_result[8], alt_result[14], 4);
-  b64_from_24bit (alt_result[3], alt_result[9], alt_result[15], 4);
-  b64_from_24bit (alt_result[4], alt_result[10], alt_result[5], 4);
-  b64_from_24bit (0, 0, alt_result[11], 2);
+  b64_from_24bit (&cp, &buflen,
+                  alt_result[0], alt_result[6], alt_result[12], 4);
+  b64_from_24bit (&cp, &buflen,
+                  alt_result[1], alt_result[7], alt_result[13], 4);
+  b64_from_24bit (&cp, &buflen,
+                  alt_result[2], alt_result[8], alt_result[14], 4);
+  b64_from_24bit (&cp, &buflen,
+                  alt_result[3], alt_result[9], alt_result[15], 4);
+  b64_from_24bit (&cp, &buflen,
+                  alt_result[4], alt_result[10], alt_result[5], 4);
+  b64_from_24bit (&cp, &buflen,
+                  0, 0, alt_result[11], 2);
   if (buflen <= 0)
     {
       __set_errno (ERANGE);