From c0e4753cfcbece7aaf2a96726146b225c9925932 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 13 Jun 2006 18:09:04 +0000 Subject: r16199: Fix Klocwork #1 - ensure we test the first strtok for NULL. Jeremy. (This used to be commit 98751e8190317416de56b4a19a489c5f4b7d6bc9) --- source3/libads/ads_struct.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'source3') diff --git a/source3/libads/ads_struct.c b/source3/libads/ads_struct.c index e546f2ae8a..7a03a2a80f 100644 --- a/source3/libads/ads_struct.c +++ b/source3/libads/ads_struct.c @@ -48,16 +48,18 @@ char *ads_build_path(const char *realm, const char *sep, const char *field, int strlcpy(ret,field, len); p=strtok(r,sep); - strlcat(ret, p, len); - - while ((p=strtok(NULL,sep))) { - char *s; - if (reverse) - asprintf(&s, "%s%s,%s", field, p, ret); - else - asprintf(&s, "%s,%s%s", ret, field, p); - free(ret); - ret = s; + if (p) { + strlcat(ret, p, len); + + while ((p=strtok(NULL,sep))) { + char *s; + if (reverse) + asprintf(&s, "%s%s,%s", field, p, ret); + else + asprintf(&s, "%s,%s%s", ret, field, p); + free(ret); + ret = s; + } } free(r); -- cgit