Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/gen PR/49185: Conrad Meyer: strvisx: Handle zero-le...
details: https://anonhg.NetBSD.org/src/rev/49ce212e4c93
branches: trunk
changeset: 332137:49ce212e4c93
user: christos <christos%NetBSD.org@localhost>
date: Mon Sep 08 16:42:09 2014 +0000
description:
PR/49185: Conrad Meyer: strvisx: Handle zero-length input strings gracefully.
(don't abuse 0 to mean compute string length internally)
diffstat:
lib/libc/gen/vis.c | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)
diffs (76 lines):
diff -r 8ab6911ec799 -r 49ce212e4c93 lib/libc/gen/vis.c
--- a/lib/libc/gen/vis.c Mon Sep 08 14:49:46 2014 +0000
+++ b/lib/libc/gen/vis.c Mon Sep 08 16:42:09 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vis.c,v 1.60 2013/02/21 16:21:20 joerg Exp $ */
+/* $NetBSD: vis.c,v 1.61 2014/09/08 16:42:09 christos Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -57,7 +57,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: vis.c,v 1.60 2013/02/21 16:21:20 joerg Exp $");
+__RCSID("$NetBSD: vis.c,v 1.61 2014/09/08 16:42:09 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#ifdef __FBSDID
__FBSDID("$FreeBSD$");
@@ -105,6 +105,7 @@
#define XTOA(c) L"0123456789ABCDEF"[c]
#define MAXEXTRAS 10
+#define MB_STRZ ((size_t)-1)
#if !HAVE_NBTOOL_CONFIG_H
#ifndef __NetBSD__
@@ -357,7 +358,7 @@
ssize_t mbslength, maxolen;
_DIAGASSERT(mbdst != NULL);
- _DIAGASSERT(mbsrc != NULL);
+ _DIAGASSERT(mbsrc != NULL || mblength == 0);
_DIAGASSERT(mbextra != NULL);
/*
@@ -375,7 +376,7 @@
/* Allocate space for the wide char strings */
psrc = pdst = extra = NULL;
- if (!mblength)
+ if (mblength == MB_STRZ)
mblength = strlen(mbsrc);
if ((psrc = calloc(mblength + 1, sizeof(*psrc))) == NULL)
return -1;
@@ -571,13 +572,13 @@
int
strsvis(char *mbdst, const char *mbsrc, int flags, const char *mbextra)
{
- return istrsenvisx(mbdst, NULL, mbsrc, 0, flags, mbextra, NULL);
+ return istrsenvisx(mbdst, NULL, mbsrc, MB_STRZ, flags, mbextra, NULL);
}
int
strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags, const char *mbextra)
{
- return istrsenvisx(mbdst, &dlen, mbsrc, 0, flags, mbextra, NULL);
+ return istrsenvisx(mbdst, &dlen, mbsrc, MB_STRZ, flags, mbextra, NULL);
}
int
@@ -646,13 +647,13 @@
int
strvis(char *mbdst, const char *mbsrc, int flags)
{
- return istrsenvisx(mbdst, NULL, mbsrc, 0, flags, "", NULL);
+ return istrsenvisx(mbdst, NULL, mbsrc, MB_STRZ, flags, "", NULL);
}
int
strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags)
{
- return istrsenvisx(mbdst, &dlen, mbsrc, 0, flags, "", NULL);
+ return istrsenvisx(mbdst, &dlen, mbsrc, MB_STRZ, flags, "", NULL);
}
/*
Home |
Main Index |
Thread Index |
Old Index