cgit_repobasename: convert to allocated result
cgit_repobasename has one user also in ui-shared.c. Make it static
and remove the declaration from cgit.h.
Instead of the gnarly return pointer to now deallocated stack,
compute the valid part of the string using the incoming pointer,
then just allocate the right amount and copy it in. Drop the
const on the return type now it's allocated.
Cover the fact the input may be garbage by returning NULL if so.
Comment the function at the start that the result may be NULL or
must be freed now.
Convert the only user, cgit_snapshot_prefix(), to the same return
convention and also comment him at the start that the result may
be NULL or must be freed. Also change the return type to char *.
Convert his only users, get_ref_from_filename() and
cgit_print_snapshot()in ui-snapshot.c, to deal with the new
result convention. cgit_print_snapshot() already did an
xstrdup() on him anyway, just remove it and check for NULL.
The reason triggering all this was
../ui-shared.c: In function ‘cgit_repobasename’:
../ui-shared.c:135:2: warning: ‘strncpy’ specified bound 1024 equals destination size [-Wstringop-truncation]
strncpy(rvbuf, reponame, sizeof(rvbuf));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ comment from John Keeping.
Signed-off-by: Andy Green <andy@warmcat.com>
4 files changed