]> granicus.if.org Git - re2c/commitdiff
Fixed bug #215 "A memory read overrun issue in s_to_n32_unsafe.cc".
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 4 Sep 2018 19:27:40 +0000 (20:27 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 4 Sep 2018 19:27:40 +0000 (20:27 +0100)
The error was in the code of the test itself: the special case of zero
wasn't handled correctrly by the function that prepares input data for
the test. As a result, zero-length input string was passed to the test,
which is unexpected: the tested function is an "unsafe" one (as the
name suggests) and is meant to be used on an already validated input.

re2c/src/test/s_to_n32_unsafe/test.cc

index 017439247f2e975f01bc74a0f5cbe17dce061751..ba4acaa06c55d95cbdb8d2104bd9e5b81a21cc57 100644 (file)
@@ -11,11 +11,15 @@ static const uint32_t DIGITS = 256;
 // no terminating null as we don't need it
 static char * u64_to_s_fastest_ever (uint64_t u, char * s)
 {
-    while (u > 0)
-    {
-        const uint64_t d = u % 10 + '0';
-        *--s = static_cast<char> (d);
-        u /= 10;
+    if (u == 0) {
+        *--s = '0';
+    }
+    else {
+        while (u > 0) {
+            const uint64_t d = u % 10 + '0';
+            *--s = static_cast<char> (d);
+            u /= 10;
+        }
     }
     return s;
 }