]> mj.ucw.cz Git - libucw.git/commitdiff
Fixed a bug in str_unesc() and added a testsuite.
authorMartin Mares <mj@ucw.cz>
Wed, 25 Jun 2008 19:50:08 +0000 (21:50 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 25 Jun 2008 19:50:08 +0000 (21:50 +0200)
Prior to this fix, the first character after an octal escape
sequence was copied literally.

lib/Makefile
lib/str-esc.c

index 6c90b319056ad48f358a04450a909394058987e2..82d3007d6b23c963771d82f046dc331c1a53921f 100644 (file)
@@ -97,7 +97,7 @@ $(o)/lib/ipaccess-test: $(o)/lib/ipaccess-test.o $(LIBUCW)
 
 TESTS+=$(addprefix $(o)/lib/,regex.test unicode.test hash-test.test mempool.test stkstring.test \
     slists.test kmp-test.test bbuf.test getopt.test fastbuf.test ff-unicode.test eltpool.test \
-    fb-socket.test)
+    fb-socket.test string.test)
 
 $(o)/lib/regex.test: $(o)/lib/regex-t
 $(o)/lib/unicode.test: $(o)/lib/unicode-t
@@ -113,6 +113,7 @@ $(o)/lib/fastbuf.test: $(o)/lib/fb-file-t $(o)/lib/fb-grow-t $(o)/lib/fb-pool-t
 $(o)/lib/ff-unicode.test: $(o)/lib/ff-unicode-t
 $(o)/lib/eltpool.test: $(o)/lib/eltpool-t
 $(o)/lib/fb-socket.test: $(o)/lib/fb-socket-t
+$(o)/lib/string.test: $(o)/lib/str-hex-t $(o)/lib/str-esc-t
 
 ifdef CONFIG_UCW_THREADS
 TESTS+=$(addprefix $(o)/lib/,asio.test)
index d2944389c241187923cf002afb7e052fa98f63a9..f9df3881583d8f64cb07de18d487e1a5376f357f 100644 (file)
@@ -65,7 +65,8 @@ str_unesc(char *d, const char *s)
                  else
                    DBG("octal escape sequence out of range");
                }
-             *d++ = *s++;
+             else
+               *d++ = *s++;
              break;
          }
       else
@@ -74,3 +75,25 @@ str_unesc(char *d, const char *s)
   *d = 0;
   return d;
 }
+
+#ifdef TEST
+
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+  if (argc < 2)
+    return 1;
+
+  char tmp[strlen(argv[1]) + 1];
+  int len = str_unesc(tmp, argv[1]) - tmp;
+
+  char hex[2*len + 1];
+  mem_to_hex(hex, tmp, len, ' ');
+  puts(hex);
+
+  return 0;
+}
+
+#endif