[libc-commits] [PATCH] D109084: [libc] fix strtointeger hex prefix parsing

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Sep 2 18:13:42 PDT 2021


sivachandra accepted this revision.
sivachandra added a comment.
This revision is now accepted and ready to land.

While it is OK for this patch, I would suggest that the tests be templatized.



================
Comment at: libc/src/__support/str_conv_utils.h:76
+  } else if (base == 16 && *src == '0' && (*(src + 1) | 32) == 'x' &&
+             isalnum(*(src + 2)) && b36_char_to_int(*(src + 2)) < 16) {
+    // There has to be a hexadecimal digit after the "0x", else the number is
----------------
I think the logic here and on line 41/42 can be moved to a single function say, `is_hex_start(...)`. Then, we can use it like this:

```
else if (base == 16 && is_hex_start(src)) {
  ...
}
```

`infer_base` will have to be modified to something like this:

```
  if (is_hex_start(*src)) {
    (*src) += 2;
    return 16;
  } else if (**src == '0') {
    ++(*src);
    return 8;
  } else {
    return 10;
  }
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109084/new/

https://reviews.llvm.org/D109084



More information about the libc-commits mailing list