-
Notifications
You must be signed in to change notification settings - Fork 16
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
minor cleanup for code scan #194
Conversation
@liquidaty: Please review. |
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
CodeQL Code Scanning Report for this branch: Apparently, the first two are fixable. |
Just verified with clang-format 18.1.3 on https://clang-format-configurator.site with our config that this line: if(err) is formatting correctly i.e.: -if(err)
+if (err) |
Looked into these CodeQL issues:
Both seem to be false positives. Tried setting the respective pointer to
parser->fixed.offsets = calloc(count, sizeof(*parser->fixed.offsets));
if (parser->fixed.offsets) {
parser->fixed.count = count;
for (unsigned i = 0; i < count; i++)
parser->fixed.offsets[i] = offsets[i];
} else {
fprintf(stderr, "Out of memory!\n");
return zsv_status_memory;
}
free(data.fixed.offsets);
data.fixed.offsets = malloc(data.fixed.count * sizeof(*data.fixed.offsets));
if (data.fixed.offsets) {
size_t count = 0;
const char *start = argv[arg_i];
for (const char *end = argv[arg_i];; end++) {
if (*end == ',' || *end == '\0') {
if (sscanf(start, "%zu,", &data.fixed.offsets[count++]) != 1) {
stat = zsv_printerr(1, "Invalid offset: %.*s\n", end - start, start);
break;
} else if (*end == '\0')
break;
else {
start = end + 1;
if (*start == '\0')
break;
}
}
}
} else {
fprintf(stderr, "Out of memory!\n");
return zsv_status_memory;
} Tested with "out of memory" check first too. No effect at all. Also, on these checks, there's this warning:
Given above, looks like these can safely be marked/dismissed as false positives from their respective links. |
if (i > 0) | ||
result = zsv_select_column_index_selection_type_single; | ||
} else { | ||
k = sscanf((const char *)arg, "%u-%n", &i, &n); | ||
if (k && n == (int)strlen((const char *)arg)) { | ||
if (k == 1 && n >= 0 && (size_t)n == strlen((const char *)arg)) { |
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.
I was wondering if n
will ever be 0 for these cases. 🤔
Checking n
against strlen()
seems to be enough.
Please see these examples:
- https://godbolt.org/z/oKn5oGGdW (with
n
check) - https://godbolt.org/z/7jT4PGzhe (without
n
check)
n
is never 0 here.
Also, the negative lower-bounded case (-5
) seems to be handled as single index.
It's being read and wrapped around as its type is unsigned int
.
Here's a sample CLI interaction:
clang-format-15