This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
BZ#15380: Fix initstate error return
- From: Andreas Jaeger <aj at suse dot com>
- To: libc-alpha <libc-alpha at sourceware dot org>
- Date: Sat, 27 Apr 2013 16:59:01 +0200
- Subject: BZ#15380: Fix initstate error return
From Bugzilla:
"POSIX.1-2001 says:
RETURN VALUE
If initstate() is called with size less than 8, it shall return
NULL.
glibc sets errno to EINVAL for this case, but does not return NULL, thus
violating the standard."
Here's a patch to fix this, ok to commit?
Andreas
2013-04-27 Andreas Jaeger <aj@suse.de>
[BZ #15380]
* stdlib/random.c (weak_alias): Return NULL if
__initstate fails.
diff --git a/stdlib/random.c b/stdlib/random.c
index 3ed610d..1083973 100644
--- a/stdlib/random.c
+++ b/stdlib/random.c
@@ -234,16 +234,17 @@ __initstate (seed, arg_state, n)
size_t n;
{
int32_t *ostate;
+ int ret;
__libc_lock_lock (lock);
ostate = &unsafe_state.state[-1];
- __initstate_r (seed, arg_state, n, &unsafe_state);
+ ret = __initstate_r (seed, arg_state, n, &unsafe_state);
__libc_lock_unlock (lock);
- return (char *) ostate;
+ return (ret == -1) ? NULL : (char *) ostate;
}
weak_alias (__initstate, initstate)
--
Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126