summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2015-03-18 22:53:27 +0000
committermillert <millert@openbsd.org>2015-03-18 22:53:27 +0000
commit76dd1399b55c04272a69b1d0466db0c87c219062 (patch)
treefe179e89203a38940bb133883bcedc4c3fd52c15
parentnl_langinfo() cannot return NULL; from Andre Smagin (diff)
downloadwireguard-openbsd-76dd1399b55c04272a69b1d0466db0c87c219062.tar.xz
wireguard-openbsd-76dd1399b55c04272a69b1d0466db0c87c219062.zip
Remove useless check for leading blanks in the month name. The
code didn't adjust len after stripping blanks so even if a month *did* start with a blank we'd end up copying garbage at the end. Also convert a malloc + memcpy to strdup and fix a memory leak in the wide char version if mbstowcs() fails. From Andre Smagin
-rw-r--r--usr.bin/sort/bwstring.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/usr.bin/sort/bwstring.c b/usr.bin/sort/bwstring.c
index ee292a014c6..6e985f3587b 100644
--- a/usr.bin/sort/bwstring.c
+++ b/usr.bin/sort/bwstring.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bwstring.c,v 1.2 2015/03/18 22:39:41 millert Exp $ */
+/* $OpenBSD: bwstring.c,v 1.3 2015/03/18 22:53:27 millert Exp $ */
/*-
* Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org>
@@ -69,14 +69,9 @@ initialise_months(void)
tmp = nl_langinfo(item[i]);
if (debug_sort)
printf("month[%d]=%s\n", i, tmp);
- len = strlen(tmp);
- if (len < 1)
+ if (*tmp == '\0')
continue;
- while (isblank((unsigned char)*tmp))
- ++tmp;
- m = sort_malloc(len + 1);
- memcpy(m, tmp, len + 1);
- m[len] = '\0';
+ m = sort_strdup(tmp);
for (j = 0; j < len; j++)
m[j] = toupper(m[j]);
cmonths[i] = m;
@@ -94,14 +89,14 @@ initialise_months(void)
tmp = nl_langinfo(item[i]);
if (debug_sort)
printf("month[%d]=%s\n", i, tmp);
- len = strlen(tmp);
- if (len < 1)
+ if (*tmp == '\0')
continue;
- while (isblank((unsigned char)*tmp))
- ++tmp;
+ len = strlen(tmp);
m = sort_malloc(SIZEOF_WCHAR_STRING(len + 1));
- if (mbstowcs(m, tmp, len) == (size_t)-1)
+ if (mbstowcs(m, tmp, len) == (size_t)-1) {
+ sort_free(m);
continue;
+ }
m[len] = L'\0';
for (j = 0; j < len; j++)
m[j] = towupper(m[j]);