[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: buffer write bug in mg



Kjell Wooding wrote:
> While I'm here, use basename() instead of some custom stuff

Building on Linux resulted in this warning:

  buffer.c:626: warning: passing arg 1 of `__xpg_basename' discards qualifiers from pointer target type


>From basename(3):

  CAVEATS
       basename() returns a pointer to internal static storage space that will
       be overwritten by subsequent calls.


So I'd like to suggest this extra patch:

--- /usr/src/usr.bin/mg/buffer.c        Tue Apr  4 11:58:14 2006
+++ buffer.c    Tue Apr  4 11:52:40 2006
@@ -622,8 +622,11 @@ baugname(char *bn, const char *fn, size_
 {
        int      count;
        size_t   remain, len;
+       char    *fn_dup;
 
-       len = strlcpy(bn, basename(fn), bs);
+       fn_dup = strdup(fn);
+       len = strlcpy(bn, basename(fn_dup), bs);
+       free(fn_dup);
        if (len >= bs)
                return (FALSE);





# Han