[SIGAR-114] set errno=0 before calling strto functions

This commit is contained in:
Doug MacEachern 2008-07-11 23:17:12 +00:00
parent 7d63d0f092
commit aa33543b58
1 changed files with 8 additions and 0 deletions

View File

@ -37,6 +37,8 @@
#include <errno.h> #include <errno.h>
#endif #endif
#define SIGAR_CLEAR_ERRNO() errno = 0
#define strtonum_failed(src, ptr) \ #define strtonum_failed(src, ptr) \
((src == ptr) || (errno == ERANGE) || (*ptr != '\0')) ((src == ptr) || (errno == ERANGE) || (*ptr != '\0'))
@ -761,6 +763,7 @@ static int ptql_branch_init_pid(ptql_parse_branch_t *parsed,
} }
else { else {
char *ptr; char *ptr;
SIGAR_CLEAR_ERRNO();
branch->data.pid = str2pid(parsed->value, ptr); branch->data.pid = str2pid(parsed->value, ptr);
if (strtonum_failed(parsed->value, ptr)) { if (strtonum_failed(parsed->value, ptr)) {
return PTQL_ERRNAN; return PTQL_ERRNAN;
@ -986,6 +989,7 @@ static int ptql_pid_get(sigar_t *sigar,
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
return status; return status;
} }
SIGAR_CLEAR_ERRNO();
*pid = str2pid(buffer, ptr); *pid = str2pid(buffer, ptr);
if ((buffer == ptr) || (errno == ERANGE)) { if ((buffer == ptr) || (errno == ERANGE)) {
return errno; return errno;
@ -1077,6 +1081,7 @@ static int ptql_args_branch_init(ptql_parse_branch_t *parsed,
else { else {
char *end; char *end;
SIGAR_CLEAR_ERRNO();
branch->data.ui32 = branch->data.ui32 =
strtol(parsed->attr, &end, 10); strtol(parsed->attr, &end, 10);
@ -1522,6 +1527,7 @@ static int ptql_branch_add(ptql_parse_branch_t *parsed,
case PTQL_VALUE_TYPE_UI64: case PTQL_VALUE_TYPE_UI64:
branch->match.ui64 = ptql_op_ui64[branch->op_name]; branch->match.ui64 = ptql_op_ui64[branch->op_name];
if (!is_set) { if (!is_set) {
SIGAR_CLEAR_ERRNO();
branch->value.ui64 = strtoull(parsed->value, &ptr, 10); branch->value.ui64 = strtoull(parsed->value, &ptr, 10);
if (strtonum_failed(parsed->value, ptr)) { if (strtonum_failed(parsed->value, ptr)) {
return PTQL_ERRNAN; return PTQL_ERRNAN;
@ -1531,6 +1537,7 @@ static int ptql_branch_add(ptql_parse_branch_t *parsed,
case PTQL_VALUE_TYPE_UI32: case PTQL_VALUE_TYPE_UI32:
branch->match.ui32 = ptql_op_ui32[branch->op_name]; branch->match.ui32 = ptql_op_ui32[branch->op_name];
if (!is_set) { if (!is_set) {
SIGAR_CLEAR_ERRNO();
branch->value.ui32 = strtoul(parsed->value, &ptr, 10); branch->value.ui32 = strtoul(parsed->value, &ptr, 10);
if (strtonum_failed(parsed->value, ptr)) { if (strtonum_failed(parsed->value, ptr)) {
return PTQL_ERRNAN; return PTQL_ERRNAN;
@ -1540,6 +1547,7 @@ static int ptql_branch_add(ptql_parse_branch_t *parsed,
case PTQL_VALUE_TYPE_DBL: case PTQL_VALUE_TYPE_DBL:
branch->match.dbl = ptql_op_dbl[branch->op_name]; branch->match.dbl = ptql_op_dbl[branch->op_name];
if (!is_set) { if (!is_set) {
SIGAR_CLEAR_ERRNO();
branch->value.dbl = strtod(parsed->value, &ptr); branch->value.dbl = strtod(parsed->value, &ptr);
if (strtonum_failed(parsed->value, ptr)) { if (strtonum_failed(parsed->value, ptr)) {
return PTQL_ERRNAN; return PTQL_ERRNAN;