Просмотр исходного кода

libdpkg: Do not add a NUL char after varbuf_printf() calls

The varbuf_printf() and varbuf_vprintf() already NUL terminate the
string via the vsnprintf() calls. No need to do that again.
Guillem Jover лет назад: 15
Родитель
Сommit
173a6cb532
3 измененных файлов с 4 добавлено и 7 удалено
  1. 0 1
      lib/dpkg/log.c
  2. 4 5
      lib/dpkg/test/t-varbuf.c
  3. 0 1
      lib/dpkg/triglib.c

+ 0 - 1
lib/dpkg/log.c

@@ -62,7 +62,6 @@ log_message(const char *fmt, ...)
 	va_start(args, fmt);
 	va_start(args, fmt);
 	varbuf_reset(&log);
 	varbuf_reset(&log);
 	varbuf_vprintf(&log, fmt, args);
 	varbuf_vprintf(&log, fmt, args);
-	varbuf_add_char(&log, '\0');
 	va_end(args);
 	va_end(args);
 
 
 	time(&now);
 	time(&now);

+ 4 - 5
lib/dpkg/test/t-varbuf.c

@@ -2,7 +2,7 @@
  * libdpkg - Debian packaging suite library routines
  * libdpkg - Debian packaging suite library routines
  * t-verbuf.c - test varbuf implementation
  * t-verbuf.c - test varbuf implementation
  *
  *
- * Copyright © 2009 Guillem Jover <guillem@debian.org>
+ * Copyright © 2009-2011 Guillem Jover <guillem@debian.org>
  *
  *
  * This is free software; you can redistribute it and/or modify
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
 #include <dpkg/test.h>
 #include <dpkg/test.h>
 #include <dpkg/varbuf.h>
 #include <dpkg/varbuf.h>
 
 
+#include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 static void
 static void
@@ -207,8 +208,7 @@ test_varbuf_printf(void)
 
 
 	/* Test normal format printing. */
 	/* Test normal format printing. */
 	varbuf_printf(&vb, "format %s number %d", "string", 10);
 	varbuf_printf(&vb, "format %s number %d", "string", 10);
-	varbuf_add_char(&vb, '\0');
-	test_pass(vb.used == sizeof("format string number 10"));
+	test_pass(vb.used == strlen("format string number 10"));
 	test_pass(vb.size >= vb.used);
 	test_pass(vb.size >= vb.used);
 	test_str(vb.buf, ==, "format string number 10");
 	test_str(vb.buf, ==, "format string number 10");
 
 
@@ -217,8 +217,7 @@ test_varbuf_printf(void)
 	/* Test concatenated format printing. */
 	/* Test concatenated format printing. */
 	varbuf_printf(&vb, "format %s number %d", "string", 10);
 	varbuf_printf(&vb, "format %s number %d", "string", 10);
 	varbuf_printf(&vb, " extra %s", "string");
 	varbuf_printf(&vb, " extra %s", "string");
-	varbuf_add_char(&vb, '\0');
-	test_pass(vb.used == sizeof("format string number 10 extra string"));
+	test_pass(vb.used == strlen("format string number 10 extra string"));
 	test_pass(vb.size >= vb.used);
 	test_pass(vb.size >= vb.used);
 	test_str(vb.buf, ==, "format string number 10 extra string");
 	test_str(vb.buf, ==, "format string number 10 extra string");
 
 

+ 0 - 1
lib/dpkg/triglib.c

@@ -423,7 +423,6 @@ trk_explicit_interest_change(const char *trig,  struct pkginfo *pkg, int signum)
 	trk_explicit_start(trig);
 	trk_explicit_start(trig);
 	varbuf_reset(&newfn);
 	varbuf_reset(&newfn);
 	varbuf_printf(&newfn, "%s/%s.new", triggersdir, trig);
 	varbuf_printf(&newfn, "%s/%s.new", triggersdir, trig);
-	varbuf_add_char(&newfn, '\0');
 
 
 	nf = fopen(newfn.buf, "w");
 	nf = fopen(newfn.buf, "w");
 	if (!nf)
 	if (!nf)