-
Notifications
You must be signed in to change notification settings - Fork 972
fix compile overflow warnings #2963
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
base: unstable
Are you sure you want to change the base?
Conversation
Signed-off-by: lizhiqiang.sf <lizhiqiang.sf@bytedance.com>
|
my complice environment is: Perhaps you could take a look. cc @rjd15372 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #2963 +/- ##
============================================
+ Coverage 73.73% 73.88% +0.14%
============================================
Files 125 125
Lines 68911 68911
============================================
+ Hits 50813 50913 +100
+ Misses 18098 17998 -100
🚀 New features to boost your workflow:
|
|
Same thing |
| sds *parts = sdssplitargs(shebang, &numparts); | ||
| sdsfree(shebang); | ||
| if (!parts || numparts == 0) { | ||
| if (!parts || numparts == 0 || sdslen(parts[0]) < 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix LGTM.
- Personally I find it more readable by trimming the shebang prefix first and then treat each argument separately eg:
--- a/src/eval.c
+++ b/src/eval.c
@@ -230,9 +230,8 @@ int evalExtractShebangFlags(sds body,
return C_ERR;
}
shebang_len = shebang_end - body;
- sds shebang = sdsnewlen(body, shebang_len);
+ sds shebang = sdsnewlen(body + 2, shebang_len - 2);
sds *parts = sdssplitargs(shebang, &numparts);
- sdsfree(shebang);
if (!parts || numparts == 0) {
if (err) *err = sdsnew("Invalid engine in script shebang");
sdsfreesplitres(parts, numparts);
@@ -240,9 +239,9 @@ int evalExtractShebangFlags(sds body,
}
if (out_engine) {
- size_t engine_name_len = sdslen(parts[0]) - 2;
+ size_t engine_name_len = sdslen(parts[0]);
*out_engine = zcalloc(engine_name_len + 1);
- valkey_strlcpy(*out_engine, parts[0] + 2, engine_name_len + 1);
+ valkey_strlcpy(*out_engine, parts[0], engine_name_len + 1);
}
script_flags &= ~SCRIPT_FLAG_EVAL_COMPAT_MODE;
- I would like if we had a len version of sdssplitargs which could help us avoid the unnecessary:
sds shebang = sdsnewlen(body, shebang_len);
as it is only created for the sdssplitargs does not except input string length and is tracking the null terminator.
Compilation warning in eval.c:244 when extracting shebang flags -
attempting to allocate 18446744073709551615 bytes (SIZE_MAX) due to
unsigned integer underflow.