On 02/04/2016 03:26 PM, Richard Henderson wrote: > On 02/05/2016 01:56 AM, Alex Bennée wrote: >> + if (g_strrstr(filename, "%d")) { >> + /* if we are going to format this we'd better validate first */ >> + if (g_regex_match_simple("^[^%]+%d[^%]+$", filename, 0, 0)) { > > Why g_strrstr instead of strstr? There should be only one, so why look > for the last?
For that matter, why use a heavyweight regex, when you can achieve the same validation with the faster: char *tmp = strchr(filename, '%'); if (tmp) { if (tmp[1] != 'd' || strchr(tmp + 2, '%')) { ...report invalid string } -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature