summaryrefslogtreecommitdiff
path: root/libguile/stime.c
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2019-04-01 22:11:35 -0400
committerMark H Weaver <mhw@netris.org>2019-04-16 16:54:55 -0400
commit6b1de860ab2360e8679205aecdc1c837744a4b9c (patch)
tree0357dcee473b12ca590343ad513d876eca1e8199 /libguile/stime.c
parent275c96dd1fbc392e43423e91f08d2cf2fcc538a1 (diff)
Avoid passing NULL to 'memcpy' and 'memcmp'.
Reported by Jeffrey Walton <noloader@gmail.com> in <https://lists.gnu.org/archive/html/guile-devel/2019-03/msg00001.html>. Note that C11 section 7.1.4 (Use of library functions) states that: "unless explicitly stated otherwise in the detailed descriptions [of library functions] that follow: If an argument to a function has an invalid value (such as ... a null pointer ...) ..., the behavior is undefined." Note that 'strxfrm' is an example of a standard C function that explicitly states otherwise, allowing NULL to be passed in the first argument if the size argument is zero, but no similar allowance is specified for 'memcpy' or 'memcmp'. * libguile/bytevectors.c (scm_uniform_array_to_bytevector): Call memcpy only if 'byte_len' is non-zero. * libguile/srfi-14.c (charsets_equal): Call memcmp only if the number of ranges is non-zero. * libguile/stime.c (setzone): Pass 1-character buffer to 'scm_to_locale_stringbuf', instead of NULL. * libguile/strings.c (scm_to_locale_stringbuf): Call memcpy only if the number of bytes to copy is non-zero.
Diffstat (limited to 'libguile/stime.c')
-rw-r--r--libguile/stime.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/libguile/stime.c b/libguile/stime.c
index 060a49642..b681d7ee3 100644
--- a/libguile/stime.c
+++ b/libguile/stime.c
@@ -340,10 +340,11 @@ setzone (SCM zone, int pos, const char *subr)
if (!SCM_UNBNDP (zone))
{
static char *tmpenv[2];
+ char dummy_buf[1];
char *buf;
size_t zone_len;
- zone_len = scm_to_locale_stringbuf (zone, NULL, 0);
+ zone_len = scm_to_locale_stringbuf (zone, dummy_buf, 0);
buf = scm_malloc (zone_len + sizeof (tzvar) + 1);
strcpy (buf, tzvar);
buf[sizeof(tzvar)-1] = '=';