From 8b44ee5f70e299a90738ebda0a87e879d6130aca Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Fri, 10 Aug 2007 00:00:14 +0000 Subject: [PATCH] Add string_or_undef() utility function. Used when setting addinfo in search handler to avoid "Use of uninitialized value in subroutine entry" warnings from Perl. Yet to be plumbed into the other handlers as I don't yet have a way of testing them. --- SimpleServer.xs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/SimpleServer.xs b/SimpleServer.xs index b3b3800..6af248f 100644 --- a/SimpleServer.xs +++ b/SimpleServer.xs @@ -1,5 +1,5 @@ /* - * $Id: SimpleServer.xs,v 1.64 2007-08-08 12:11:42 mike Exp $ + * $Id: SimpleServer.xs,v 1.65 2007-08-10 00:00:14 mike Exp $ * ---------------------------------------------------------------------- * * Copyright (c) 2000-2004, Index Data. @@ -92,6 +92,28 @@ PerlInterpreter *root_perl_context; #define GRS_BUF_SIZE 8192 + +/* + * Inspects the SV indicated by svp, and returns a null pointer if + * it's an undefined value, or a string allocation from `stream' + * otherwise. Using this when filling in addinfo avoids those + * irritating "Use of uninitialized value in subroutine entry" + * warnings from Perl. + */ +char *string_or_undef(SV **svp, ODR stream) { + STRLEN len; + char *ptr, *buf; + + if (!SvOK(*svp)) + return 0; + + ptr = SvPV(*svp, len); + buf = (char*) odr_malloc(stream, len+1); + strcpy(buf, ptr); + return buf; +} + + CV * simpleserver_sv2cv(SV *handler) { STRLEN len; char *buf; @@ -679,12 +701,9 @@ int bend_search(void *handle, bend_search_rr *rr) HV *href; AV *aref; SV **temp; - char *ODR_errstr; - STRLEN len; int i; char **basenames; WRBUF query; - char *ptr; SV *point; Zfront_handle *zhandle = (Zfront_handle *)handle; CV* handler_cv = 0; @@ -754,10 +773,7 @@ int bend_search(void *handle, bend_search_rr *rr) rr->errcode = SvIV(*temp); temp = hv_fetch(href, "ERR_STR", 7, 1); - ptr = SvPV(*temp, len); - ODR_errstr = (char *)odr_malloc(rr->stream, len + 1); - strcpy(ODR_errstr, ptr); - rr->errstring = ODR_errstr; + rr->errstring = string_or_undef(temp, rr->stream); temp = hv_fetch(href, "HANDLE", 6, 1); point = newSVsv(*temp); -- 1.7.10.4