Hello,

atoi is deprecated in favour of strtol because its behaviour is undefined in case it cannot represent the string value as an integer. So to avoid this i was thinking of introducing an uwsgi_atoi wrapper over strtol like the one below and convert atoi users to uwsgi_atoi. What do you think?

diff --git a/core/utils.c b/core/utils.c
index 0715b5b..123e501 100755
--- a/core/utils.c
+++ b/core/utils.c
@@ -4574,3 +4574,23 @@ int uwsgi_versionsort(const struct dirent **da, const struct dirent **db) {
         }
 }
 #endif
+
+int uwsgi_atoi(char *str) {
+       char *end;
+       long int num = strtol(str, &end, 10);
+       if (*end) {
+               uwsgi_error("uwsgi_atoi() unconverted string");
+               goto exit;
+       }
+       if (num == LONG_MIN || num < INT_MIN) {
+               uwsgi_error("uwsgi_atoi() underflow");
+               goto exit;
+       }
+       if (num == LONG_MAX || num > INT_MAX) {
+               uwsgi_error("uwsgi_atoi() overflow");
+               goto exit;
+       }
+       return (int) num;
+exit:
+       exit(1);
+}

--
Riccardo Magliocchetti
@rmistaken
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to