List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:April 6 2011 8:03pm
Subject:bzr commit into mysql-trunk branch (alexander.nozdrin:3331) WL#5787
View as plain text  
#At file:///home/alik/MySQL/bzr/00/wl5787/mysql-trunk-wl5787/ based on revid:alexander.nozdrin@stripped

 3331 Alexander Nozdrin	2011-04-07
      Preliminatry patch for WL#5787 (IPv6-capable INET_ATON and
      INET_NTOA functions).
      
      Polishing legacy code (Item_func_inet_aton & Item_func_inet_ntoa).
      No real changes.

    modified:
      sql/item_inetfunc.cc
=== modified file 'sql/item_inetfunc.cc'
--- a/sql/item_inetfunc.cc	2011-04-06 17:41:16 +0000
+++ b/sql/item_inetfunc.cc	2011-04-06 20:03:33 +0000
@@ -23,45 +23,54 @@
 
 longlong Item_func_inet_aton::val_int()
 {
-  DBUG_ASSERT(fixed == 1);
-  uint byte_result = 0;
-  ulonglong result = 0;			// We are ready for 64 bit addresses
+  DBUG_ASSERT(fixed);
+
+  uint byte_result= 0;
+  ulonglong result= 0;
   const char *p,* end;
-  char c = '.'; // we mark c to indicate invalid IP in case length is 0
+  char c= '.'; // we mark c to indicate invalid IP in case length is 0
   char buff[36];
   int dot_count= 0;
 
-  String *s, tmp(buff, sizeof(buff), &my_charset_latin1);
-  if (!(s = args[0]->val_str_ascii(&tmp)))       // If null value
+  String tmp(buff, sizeof (buff), &my_charset_latin1);
+  String *s= args[0]->val_str_ascii(&tmp);
+
+  if (!s)       // If null value
     goto err;
-  null_value=0;
 
-  end= (p = s->ptr()) + s->length();
+  null_value= 0;
+
+  p= s->ptr();
+  end= p + s->length();
   while (p < end)
   {
-    c = *p++;
-    int digit = (int) (c - '0');
+    c= *p++;
+    int digit= (int) (c - '0');
     if (digit >= 0 && digit <= 9)
     {
-      if ((byte_result = byte_result * 10 + digit) > 255)
-	goto err;				// Wrong address
+      byte_result= byte_result * 10 + digit;
+      if (byte_result > 255)
+        goto err;                               // Wrong address
     }
     else if (c == '.')
     {
       dot_count++;
       result= (result << 8) + (ulonglong) byte_result;
-      byte_result = 0;
+      byte_result= 0;
     }
     else
-      goto err;					// Invalid character
+      goto err;                                 // Invalid character
   }
-  if (c != '.')					// IP number can't end on '.'
+  if (c != '.')                                 // IP number can't end on '.'
   {
     /*
-      Handle short-forms addresses according to standard. Examples:
-      127		-> 0.0.0.127
-      127.1		-> 127.0.0.1
-      127.2.1		-> 127.2.0.1
+      Attempt to support short-form addresses (i.e. classful addresses).
+      The current code does not support full range of classful addresses.
+      Examples:
+        127     -> 0.0.0.127
+        127.255 -> 127.0.0.255
+        127.256 -> NULL (should have been 127.0.1.0)
+        127.2.1 -> 127.2.0.1
     */
     switch (dot_count) {
     case 1: result<<= 8; /* Fall through */
@@ -79,10 +88,9 @@ err:
 
 String* Item_func_inet_ntoa::val_str(String* str)
 {
-  DBUG_ASSERT(fixed == 1);
-  uchar buf[8], *p;
-  ulonglong n = (ulonglong) args[0]->val_int();
-  char num[4];
+  DBUG_ASSERT(fixed);
+
+  ulonglong n= (ulonglong) args[0]->val_int();
 
   /*
     We do not know if args[0] is NULL until we have called
@@ -90,31 +98,38 @@ String* Item_func_inet_ntoa::val_str(Str
 
     Also return null if n > 255.255.255.255
   */
-  if ((null_value= (args[0]->null_value || n > (ulonglong) LL(4294967295))))
-    return 0;					// Null value
+  null_value= args[0]->null_value || n > (ulonglong) LL(4294967295);
+
+  if (null_value)
+    return 0;                                   // Null value
 
   str->set_charset(collation.collation);
   str->length(0);
-  int4store(buf,n);
+
+  uchar buf[8];
+  int4store(buf, n);
 
   /* Now we can assume little endian. */
 
-  num[3]='.';
-  for (p=buf+4 ; p-- > buf ; )
+  char num[4];
+  num[3]= '.';
+
+  for (uchar *p= buf + 4; p-- > buf;)
   {
-    uint c = *p;
-    uint n1,n2;					// Try to avoid divisions
-    n1= c / 100;				// 100 digits
-    c-= n1*100;
-    n2= c / 10;					// 10 digits
-    c-=n2*10;					// last digit
-    num[0]=(char) n1+'0';
-    num[1]=(char) n2+'0';
-    num[2]=(char) c+'0';
+    uint c= *p;
+    uint n1, n2;                                // Try to avoid divisions
+    n1= c / 100;                                // 100 digits
+    c -= n1 * 100;
+    n2= c / 10;                                 // 10 digits
+    c -= n2 * 10;                               // last digit
+    num[0]= (char) n1 + '0';
+    num[1]= (char) n2 + '0';
+    num[2]= (char) c + '0';
     uint length= (n1 ? 4 : n2 ? 3 : 2);         // Remove pre-zero
     uint dot_length= (p <= buf) ? 1 : 0;
-    (void) str->append(num + 4 - length, length - dot_length,
-                       &my_charset_latin1);
+
+    str->append(num + 4 - length, length - dot_length, &my_charset_latin1);
   }
+
   return str;
 }


Attachment: [text/bzr-bundle] bzr/alexander.nozdrin@oracle.com-20110406200333-96ecwskvyzk8y2pp.bundle
Thread
bzr commit into mysql-trunk branch (alexander.nozdrin:3331) WL#5787Alexander Nozdrin6 Apr