From cee447066f05808d8777aa1a097eecb8fdb0054b Mon Sep 17 00:00:00 2001 From: leitner Date: Fri, 29 Sep 2023 17:25:40 +0000 Subject: [PATCH] get rid of undefined behavior regarding -INT_MAX --- scan/scan_int.c | 2 +- scan/scan_longn.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scan/scan_int.c b/scan/scan_int.c index 93f809f..12ca075 100644 --- a/scan/scan_int.c +++ b/scan/scan_int.c @@ -38,7 +38,7 @@ size_t scan_int(const char* src,int* dest) { ok=1; } if (!ok) return 0; - *dest=(neg?-l:l); + *dest=(neg?-(unsigned int)l:l); return (size_t)(tmp-src); } diff --git a/scan/scan_longn.c b/scan/scan_longn.c index bc00c0d..f85b7d9 100644 --- a/scan/scan_longn.c +++ b/scan/scan_longn.c @@ -39,6 +39,6 @@ size_t scan_longn(const char *src,size_t len,long *dest) { ok=1; } if (!ok) return 0; - *dest=(neg?-l:l); + *dest=(neg?-(unsigned long int)l:l); return (size_t)(tmp-src); }