[polypaudio-commits] r1006 - /trunk/src/polyp/xmalloc.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Fri Jun 2 17:59:26 PDT 2006
Author: lennart
Date: Sat Jun 3 02:59:24 2006
New Revision: 1006
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1006&root=polypaudio&view=rev
Log:
fix pa_xstrndup() implementation to not access potentially uninitialized memory
Modified:
trunk/src/polyp/xmalloc.c
Modified: trunk/src/polyp/xmalloc.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/xmalloc.c?rev=1006&root=polypaudio&r1=1005&r2=1006&view=diff
==============================================================================
--- trunk/src/polyp/xmalloc.c (original)
+++ trunk/src/polyp/xmalloc.c Sat Jun 3 02:59:24 2006
@@ -106,19 +106,18 @@
}
char *pa_xstrndup(const char *s, size_t l) {
+ char *e, *r;
+
if (!s)
return NULL;
- else {
- char *r;
- size_t t = strlen(s);
- if (t > l)
- t = l;
-
- r = pa_xmemdup(s, t+1);
- r[t] = 0;
- return r;
- }
+ if ((e = memchr(s, 0, l)))
+ return pa_xmemdup(s, e-s+1);
+
+ r = pa_xmalloc(l+1);
+ memcpy(r, s, l);
+ r[l] = 0;
+ return r;
}
void pa_xfree(void *p) {
More information about the pulseaudio-commits
mailing list