Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot handle UINT_MAX #7

Open
GoogleCodeExporter opened this issue Mar 23, 2015 · 1 comment
Open

Cannot handle UINT_MAX #7

GoogleCodeExporter opened this issue Mar 23, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

The function evcpe_type_validate() cannot handle the UINT_MAX 4294967295 number.
In order to reproduce, try to make a call to evcpe_attr_set() on an unsignedInt 
pareameter. The following message will be displayed:
not a positive integer: -1.

I've patched the function in order to use the strtoul() but with more check as 
suggested in one  of the site that I've visited:

int evcpe_strtoul(const char *str, int base, unsigned long *ul)
{
   char          *bad_char = NULL;
   unsigned long num = 0;

   if (!str || !ul || (base > 36) || (base < 0))
   {
      return -1;
   }

   errno = 0;
   num = strtoul(str, &bad_char, base);
   if(ERANGE == errno)
   {
      if((0 == num) && (str == bad_char))
      {
         evcpe_error(__func__, "cannot convert the string: %s", str);
      }
      else if(ULONG_MAX == num)
      {
         evcpe_error(__func__, "an overflow has been detected");
      }
   }
   else if((0 == errno) && ((NULL != bad_char) && ('\0' == *bad_char)))
   {
      *ul = num;
      return 0;
   }

   evcpe_error(__func__, "cannot convert the string: %s", str);

   return -1;
}


Original issue reported on code.google.com by [email protected] on 29 Aug 2011 at 1:18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant