static int __media_svc_safe_atoi(char *buffer, int *si)
{
- char *end;
+ char *end = NULL;
errno = 0;
+ media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
+
const long sl = strtol(buffer, &end, 10);
- if (end == buffer) {
- media_svc_error("not a decimal number");
- return MS_MEDIA_ERR_INTERNAL;
- } else if ('\0' != *end) {
- media_svc_error("extra characters at end of input: %s", end);
- return MS_MEDIA_ERR_INTERNAL;
- } else if ((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno)) {
- media_svc_error("out of range of type long");
- return MS_MEDIA_ERR_INTERNAL;
- } else if (sl > INT_MAX) {
- media_svc_error("greater than INT_MAX");
- return MS_MEDIA_ERR_INTERNAL;
- } else if (sl < INT_MIN) {
- media_svc_error("less than INT_MIN");
- return MS_MEDIA_ERR_INTERNAL;
- } else {
- *si = (int)sl;
- }
+ media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
+ media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
+ media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
+ media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
+ media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
+
+ *si = (int)sl;
+
return MS_MEDIA_ERR_NONE;
}