On Mon, 01 Dec 2014 12:23:01 +0100, Otto Moerbeek wrote:

> > (gdb) list
> > 4992            sprintf(textptr, "net:");
> > 4993            textptr = devicetext + strlen(devicetext);
> > 4994          }
> > 4995        
> > 4996          snprintf(buf, sizeof(buf), ":%s", devname);
> > 4997          snprintf(buf, sizeof(buf), "/%s", (strrchr(buf, ':')+1));
> > 4998          sprintf(textptr, "%s", (strrchr(buf, '/')+1));
> > 4999        
> > 5000          xsane.device_text = strdup(devicetext);
> > 5001
> 
> The snprintf on line 4997 copies into the same buf it is reading from.

That code would be better written as something like this:

    cp = strrchr(devname, ':');
    snprintf(buf, sizeof(buf), "/%s", cp ? cp + 1 : devname);

 - todd

Reply via email to