Closed komainu8 closed 7 years ago
atoi
returns signed int
, strtoull
returns unsigned long long
.
Negative integer's string value(e.g. "-1") becomes huge positive integer.
How about using strtoll
instead?
Thank you very much for your comment. I'm in favor of your idea.
When using strtoll
instead atoi
, type of memfree
and memcached
likely need change to uint64_t
to int64_t
.So, I modified type of memfree
and memcached
too.
:+1: Thanks!
Dear,
I suggest modify function from
atoi
tostrtoull
. Because I thinkstrtoull
is safer thanatoi
.For example, when data model of LLP64 or LP64, size of return value of
atoi
is 32bit(-2147483648 - +2147483647). (Because type of return value ofatoi
is int).And unit of "MemFree" and "Cashed" are "kb".So, the maximum that can be converted size are about 2TB with
atoi
.Memory size of many 64bit system is over 2TB.So,
atoi
have maybe occurred over flow when a computer have over 2TB memory.When
atoi
occurred over flow, action ofatoi
is undefined. So, I think suggest usestrtoull
insteadatoi
.