diff options
Diffstat (limited to 'pcilib/value.c')
-rw-r--r-- | pcilib/value.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/pcilib/value.c b/pcilib/value.c index 1a8cc45..42e7993 100644 --- a/pcilib/value.c +++ b/pcilib/value.c @@ -8,6 +8,7 @@ #include "value.h" #include "error.h" #include "unit.h" +#include "tools.h" void pcilib_clean_value(pcilib_t *ctx, pcilib_value_t *val) { if (!val) return; @@ -235,11 +236,22 @@ int pcilib_convert_value_type(pcilib_t *ctx, pcilib_value_t *val, pcilib_value_t case PCILIB_TYPE_LONG: switch (val->type) { case PCILIB_TYPE_STRING: - if (sscanf(val->sval, "%li", &val->ival) != 1) { + if (pcilib_isnumber(val->sval)) { + if (sscanf(val->sval, "%li", &val->ival) != 1) { + pcilib_warning("Can't convert string (%s) to int", val->sval); + return PCILIB_ERROR_INVALID_DATA; + } + val->format = NULL; + } else if (pcilib_isxnumber(val->sval)) { + if (sscanf(val->sval, "%lx", &val->ival) != 1) { + pcilib_warning("Can't convert string (%s) to int", val->sval); + return PCILIB_ERROR_INVALID_DATA; + } + val->format = "0x%lx"; + } else { pcilib_warning("Can't convert string (%s) to int", val->sval); return PCILIB_ERROR_INVALID_DATA; } - val->format = NULL; break; case PCILIB_TYPE_DOUBLE: val->ival = round(val->fval); |