Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

counter integer overflow? #7

Open
Triple-Z opened this issue Dec 2, 2021 · 2 comments
Open

counter integer overflow? #7

Triple-Z opened this issue Dec 2, 2021 · 2 comments

Comments

@Triple-Z
Copy link

Triple-Z commented Dec 2, 2021

Is possible that the integer counter would be overflowed to be negative?

@fffonion
Copy link
Collaborator

fffonion commented Dec 2, 2021

@Triple-Z the value stored in shdict is a double https://github.com/openresty/lua-nginx-module/blob/master/src/ngx_http_lua_shdict.c#L1795, it should be sufficient for most use cases.

@Triple-Z
Copy link
Author

Triple-Z commented Dec 3, 2021

@fffonion Thank you for your reply.

I still have two questions:

  1. In lua.org, it said that when using double to represent an integer, it won't get rounding error unless the number is greater than 10^14. As the counter value is integer, is the maximum value for the counter is 10^14 - 1?If the counter is over the 10^14, should I reset it to zero?
  2. My second question is about double overflow. However, I just learned that double overflow is not like integer overflow (INT_MAX -> INT_MIN), more like a rounding error. So the second question is just like the first question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants