From 9844049cb181d296840cf1a0e718bf960ca67ceb Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Fri, 11 Aug 2017 10:16:50 -0500 Subject: [PATCH] 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 --- CHANGELOG | 3 +++ src/core/def.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 4147687c..29ec34bc 100644 --- a/CHANGELOG +++ b/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 diff --git a/src/core/def.c b/src/core/def.c index d3004d4d..ef1d9e0b 100644 --- a/src/core/def.c +++ b/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;