List:Internals« Previous MessageNext Message »
From:Lars Thalmann Date:October 31 2005 7:58pm
Subject:bk commit into 5.0 tree (lars:1.1955)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of lthalmann. When lthalmann does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1955 05/10/31 19:57:57 lars@stripped +1 -0
  Fixed failure of NDB config retrieval.
  1. Made sure that base64 string is terminated with NUL.
  2. Made calculation of needed size for base64 string exact.
  Added checks in test for the above two fixes.

  mysys/base64.c
    1.10 05/10/31 19:57:21 lars@stripped +14 -4
    Made sure that base64 string is terminated with NUL.
    Made calculation of needed size for base64 string exact.
    Added checks in test for the above two fixes.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	lars
# Host:	dl145j.mysql.com
# Root:	/users/lthalmann/bk/mysql-5.0-base64

--- 1.9/mysys/base64.c	2005-10-25 11:30:16 +02:00
+++ 1.10/mysys/base64.c	2005-10-31 19:57:21 +01:00
@@ -27,9 +27,13 @@
 int
 base64_needed_encoded_length(int length_of_data)
 {
-  return ceil(length_of_data * 4 / 3) /* base64 chars */ +
-    ceil(length_of_data / (76 * 3 / 4)) /* Newlines */ +
-    3 /* Padding */;
+  int nb_base64_chars;
+  nb_base64_chars= (length_of_data + 2) / 3 * 4;
+
+  return
+    nb_base64_chars +            /* base64 char incl padding */
+    (nb_base64_chars - 1)/ 76 +  /* newlines */
+    1;                           /* NUL termination of string */
 }
 
 
@@ -89,6 +93,7 @@
     else
       *dst++= base64_table[(c >> 0) & 0x3f];
   }
+  *dst= '\0';
 
   return 0;
 }
@@ -209,6 +214,7 @@
   size_t j;
   size_t k, l;
   size_t dst_len;
+  size_t needed_length;
 
   for (i= 0; i < 500; i++)
   {
@@ -227,8 +233,12 @@
     }
 
     /* Encode */
-    str= (char *) malloc(base64_needed_encoded_length(src_len));
+    needed_length= base64_needed_encoded_length(src_len);
+    str= (char *) malloc(needed_length);
+    for (k= 0; k < needed_length; k++)
+      str[k]= 0xff; /* Fill memory to check correct NUL termination */
     require(base64_encode(src, src_len, str) == 0);
+    require(needed_length == strlen(str) + 1);
 
     /* Decode */
     dst= (char *) malloc(base64_needed_decoded_length(strlen(str)));
Thread
bk commit into 5.0 tree (lars:1.1955)Lars Thalmann31 Oct