On 07/02/10 - 12:33:31PM, Eric Blake (cygwin) wrote:
> On 07/02/2010 09:18 AM, Chris Lalancette wrote:
> > +        if (tmp[0] == '\0') {
> > +            qemuReportError(VIR_ERR_INTERNAL_ERROR,
> > +                            "%s", _("Empty qemu environment name 
> > specified"));
> > +            goto error;
> > +        }
> > +        if (strspn(tmp, 
> > "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_") == 0) {
> > +            qemuReportError(VIR_ERR_INTERNAL_ERROR,
> > +                            "%s", _("Invalid environment name, it must 
> > begin with a letter or underscore"));
> > +            goto error;
> > +        }
> 
> Rather than using strspn here, why not go with a more efficient
> c_isdigit()?  For that matter, checking tmp[0]!='\0' can be subsumed by
> the c_isdigit(tmp[0]), but then your error messages would have to be merged.

I think we really want to use c_isalpha() + _, since those are the valid
characters for an environment variable.  !c_isdigit would only disallow digits,
while allowing other symbols like @, #, etc.

In any case, it is a good idea; we really only need to look at the first letter
for this particular check, so I've changed the logic.

--
Chris Lalancette

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to