From: Martin Mares Date: Wed, 25 Jun 2008 19:50:08 +0000 (+0200) Subject: Fixed a bug in str_unesc() and added a testsuite. X-Git-Tag: holmes-import~415 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ba770b46f3f4d25622d98a46970100d2ca1cc224;p=libucw.git Fixed a bug in str_unesc() and added a testsuite. Prior to this fix, the first character after an octal escape sequence was copied literally. --- diff --git a/lib/Makefile b/lib/Makefile index 6c90b319..82d3007d 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -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) diff --git a/lib/str-esc.c b/lib/str-esc.c index d2944389..f9df3881 100644 --- a/lib/str-esc.c +++ b/lib/str-esc.c @@ -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 +#include + +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