Browse Source

lwip_itoa: fix converting 0 (bug #51729)

lwip_itoa would output the number 0 as \0.  This fixes the issue by
adding a special check before the normal conversion loop

This was found via shell cmd idxtoname and win32 port.  "lo0" should
be returned for index 1
Joel Cunningham 8 years ago
parent
commit
9844049cb1
2 changed files with 8 additions and 0 deletions
  1. 3 0
      CHANGELOG
  2. 5 0
      src/core/def.c

+ 3 - 0
CHANGELOG

@@ -71,6 +71,9 @@ HISTORY
 
   ++ Bugfixes:
 
+  2017-08-11: Joel Cunningham
+  * lwip_itoa: fix converting the number 0 (previously converted to '\0') (bug #51729)
+
   2017-08-08: Dirk Ziegelmeier
   * ip4_route_src: parameter order is reversed: ip4_route_src(dest, src) -> ip4_route_src(src, dest)
     to make parameter order consistent with other ip*_route*() functions

+ 5 - 0
src/core/def.c

@@ -217,6 +217,11 @@ lwip_itoa(char* result, size_t bufsize, int number)
   /* create the string in a temporary buffer since we don't know how long
      it will get */
   tmp = &result[bufsize-2];
+  if (n == 0) {
+    *tmp = '0';
+    tmp--;
+    result_len++;
+  }
   while ((n != 0) && (result_len < (bufsize - 1))) {
     char val = (char)('0' + (n % 10));
     *tmp = val;