utzig commented on a change in pull request #2180: sys/config: Support for 
unsigned integer types
URL: https://github.com/apache/mynewt-core/pull/2180#discussion_r378322864
 
 

 ##########
 File path: sys/config/src/config.c
 ##########
 @@ -194,6 +196,34 @@ conf_value_from_str(char *val_str, enum conf_type type, 
void *vp, int maxlen)
         }
         *(int64_t *)vp = val64;
         break;
+    case CONF_UINT8:
+    case CONF_UINT16:
+    case CONF_UINT32:
+        uval = strtoul(val_str, &eptr, 0);
+        if (*eptr != '\0') {
+            goto err;
+        }
+        if (type == CONF_UINT8) {
+            if (uval > UINT8_MAX) {
+                goto err;
+            }
+            *(uint8_t *)vp = uval;
+        } else if (type == CONF_UINT16) {
+            if (uval > UINT16_MAX) {
+                goto err;
+            }
+            *(uint16_t *)vp = uval;
+        } else if (type == CONF_UINT32) {
+            *(uint32_t *)vp = uval;
+        }
+        break;
+    case CONF_UINT64:
+        uval64 = strtoull(val_str, &eptr, 0);
 
 Review comment:
   I see there's special handling for `UINT64` here and also for `INT64` above, 
but I am not sure why you can't just use `strtoll` for all of them.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to