jubatus / jubatus_core

Jubatus algorithm component
GNU Lesser General Public License v2.1
20 stars 29 forks source link

Improve process of convert string to number. #377

Closed komainu8 closed 7 years ago

komainu8 commented 7 years ago

Dear,

I suggest modify function from atoi to strtoull. Because I think strtoull is safer than atoi.

For example, when data model of LLP64 or LP64, size of return value of atoi is 32bit(-2147483648 - +2147483647). (Because type of return value of atoi 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 of atoi is undefined. So, I think suggest use strtoull instead atoi.

kumagi commented 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?

komainu8 commented 7 years ago

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.

kmaehashi commented 7 years ago

:+1: Thanks!