[syslinux] [PATCH] Make com32 printf obey width-restriction on %s
Arne Georg Gleditsch
arne.gleditsch at dolphinics.no
Thu Apr 12 03:59:46 PDT 2007
Hi,
The following patch is against 3.36. It lets the width-modifier to the
%s conversion specifier restrict the length of the formatted string as
well as expand it. In addition, it adds the strnlen function, which
only exists as a prototype today.
--
Arne.
--- syslinux-3.36/com32/lib/Makefile.orig 2007-02-10 21:47:07.000000000
+0100
+++ syslinux-3.36/com32/lib/Makefile 2007-04-12 12:06:07.000000000 +0200
@@ -11,7 +11,7 @@
perror.o printf.o puts.o qsort.o realloc.o seed48.o snprintf.o \
sprintf.o srand48.o sscanf.o stack.o strcasecmp.o strcat.o \
strchr.o strcmp.o strcpy.o strdup.o strerror.o strlen.o \
- strncasecmp.o strncat.o strncmp.o strncpy.o strndup.o \
+ strncasecmp.o strncat.o strncmp.o strncpy.o strndup.o strnlen.o \
strntoimax.o strntoumax.o strrchr.o strsep.o strspn.o strstr.o \
strtoimax.o strtok.o strtol.o strtoll.o strtoul.o strtoull.o \
strtoumax.o vfprintf.o vprintf.o vsnprintf.o vsprintf.o \
--- syslinux-3.36/com32/lib/vsnprintf.c.orig 2007-02-10
21:47:08.000000000 +0100
+++ syslinux-3.36/com32/lib/vsnprintf.c 2007-04-12 12:08:54.000000000 +0200
@@ -362,7 +362,7 @@
case 's': /* String */
sarg = va_arg(ap, const char *);
sarg = sarg ? sarg : "(null)";
- slen = strlen(sarg);
+ slen = width ? strnlen(sarg, width) : strlen(sarg);
goto is_string;
is_string:
--- syslinux-3.36/com32/lib/strnlen.c.orig 2007-04-12 12:07:18.000000000
+0200
+++ syslinux-3.36/com32/lib/strnlen.c 2007-04-12 12:05:41.000000000 +0200
@@ -0,0 +1,14 @@
+/*
+ * strnlen.c
+ */
+
+#include <string.h>
+
+size_t strnlen(const char *s, size_t maxlen)
+{
+ const char *ss = s;
+ while ( *ss && maxlen ) {
+ ss++; maxlen--;
+ }
+ return ss-s;
+}
More information about the Syslinux
mailing list