Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 64230fe

Browse files
committed
Fix type mismatch with strtoul and strstr
Clang (and the standard) require that the return value of strstr be a const char * if the first argument is const, and char * if it is not. However, strtoul is not updated from the C definition in a similar way, causing a type mismatch. This commit resolves that mismatch by making p const and adding an additional endptr variable for the out parameter of strtoul.
1 parent dfa9e9e commit 64230fe

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/adaptations/device-layer/GeneralUtils.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ WEAVE_ERROR ParseCompilerDateStr(const char * dateStr, uint16_t & year, uint8_t
3131
{
3232
WEAVE_ERROR err = WEAVE_NO_ERROR;
3333
char monthStr[4];
34-
char * p;
34+
const char * p;
35+
char* endptr;
3536

3637
static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
3738

@@ -45,11 +46,11 @@ WEAVE_ERROR ParseCompilerDateStr(const char * dateStr, uint16_t & year, uint8_t
4546

4647
month = ((p - months) / 3) + 1;
4748

48-
dayOfMonth = strtoul(dateStr + 4, &p, 10);
49-
VerifyOrExit(p == dateStr + 6, err = WEAVE_ERROR_INVALID_ARGUMENT);
49+
dayOfMonth = strtoul(dateStr + 4, &endptr, 10);
50+
VerifyOrExit(endptr == dateStr + 6, err = WEAVE_ERROR_INVALID_ARGUMENT);
5051

51-
year = strtoul(dateStr + 7, &p, 10);
52-
VerifyOrExit(p == dateStr + 11, err = WEAVE_ERROR_INVALID_ARGUMENT);
52+
year = strtoul(dateStr + 7, &endptr, 10);
53+
VerifyOrExit(endptr == dateStr + 11, err = WEAVE_ERROR_INVALID_ARGUMENT);
5354

5455
exit:
5556
return err;

0 commit comments

Comments
 (0)