[geos-devel] gstrdup in CAPI implementation

strk strk at keybit.net
Wed Jun 23 12:16:45 EDT 2010


I haven't investigated much, but valgrind
is complaining about some non-null-terminated
strings coming out from WKBWriter::writeHEX.

I guess it _might_ be expected, given writeHEX
takes a size_t output parameter, but wanted
to make sure this is the case.

I find it pretty useless for an HEX-returning 
function to skip null-termination (let alone
return by unsigned char*). But this is another
story.

So, question is: are gstrdup and gstrdup_s
functions in geos_ts.cpp intended to include
or not a null termination ?
Note that gstrdup_s takes a size but reads
one more byte from input pointer:

char* gstrdup_s(const char* str, const std::size_t size)
{
    char* out = static_cast<char*>(std::malloc(size + 1));
    if (0 != out)
    {
        // as no strlen call necessary, memcpy may be faster than strcpy
        std::memcpy(out, str, size + 1);
            ^^^^^^^^^^^^^^^^^ HERE ^^^^^^^^^
    }

    assert(0 != out);
    return out;
}


--strk;

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html


More information about the geos-devel mailing list