diff options
author | Eric van Gyzen <vangyzen@FreeBSD.org> | 2016-12-01 16:54:02 +0000 |
---|---|---|
committer | Eric van Gyzen <vangyzen@FreeBSD.org> | 2016-12-01 16:54:02 +0000 |
commit | 71500aab3e2064c0e603fe74c794c5f2d6090583 (patch) | |
tree | 5003834ee04b952cad62cfbcdf1849b442760ccc /usr.bin | |
parent | 007dbc1f1833bf5afc4c1f11f4e181407fdb47ed (diff) | |
download | src-71500aab3e2064c0e603fe74c794c5f2d6090583.tar.gz src-71500aab3e2064c0e603fe74c794c5f2d6090583.zip |
Notes
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/locale/locale.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/usr.bin/locale/locale.c b/usr.bin/locale/locale.c index de31eac9497e..69ec7e89cf69 100644 --- a/usr.bin/locale/locale.c +++ b/usr.bin/locale/locale.c @@ -495,29 +495,29 @@ format_grouping(const char *binary) { static char rval[64]; const char *cp; - size_t len; + size_t roff; + int len; rval[0] = '\0'; + roff = 0; for (cp = binary; *cp != '\0'; ++cp) { - char group[sizeof("127;")]; - snprintf(group, sizeof(group), "%hhd;", *cp); - len = strlcat(rval, group, sizeof(rval)); - if (len >= sizeof(rval)) { - len = sizeof(rval) - 1; - break; - } - if (*cp == CHAR_MAX) { - break; - } + if (*cp < 0) + break; /* garbage input */ + len = snprintf(&rval[roff], sizeof(rval) - roff, "%u;", *cp); + if (len < 0 || (unsigned)len >= sizeof(rval) - roff) + break; /* insufficient space for output */ + roff += len; + if (*cp == CHAR_MAX) + break; /* special termination */ } - /* Remove the trailing ';'. */ - rval[len - 1] = '\0'; + /* Truncate at the last successfully snprintf()ed semicolon. */ + if (roff != 0) + rval[roff - 1] = '\0'; - return (rval); + return (&rval[0]); } - /* * keyword value lookup helper (via localeconv()) */ |