Skip to content

Commit

Permalink
[ruby/prism] Fix up more clang-analyzer failures
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Apr 17, 2024
1 parent d6debba commit f34409b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
49 changes: 30 additions & 19 deletions prism/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,40 @@ pm_options_command_line_set(pm_options_t *options, uint8_t command_line) {
*/
PRISM_EXPORTED_FUNCTION bool
pm_options_version_set(pm_options_t *options, const char *version, size_t length) {
if (version == NULL && length == 0) {
options->version = PM_OPTIONS_VERSION_LATEST;
return true;
}
switch (length) {
case 0:
if (version == NULL) {
options->version = PM_OPTIONS_VERSION_LATEST;
return true;
}

if (length == 5) {
if (strncmp(version, "3.3.0", length) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_3_3_0;
return true;
}
return false;
case 5:
assert(version != NULL);

if (strncmp(version, "3.4.0", length) == 0) {
options->version = PM_OPTIONS_VERSION_LATEST;
return true;
}
}
if (strncmp(version, "3.3.0", length) == 0) {
options->version = PM_OPTIONS_VERSION_CRUBY_3_3_0;
return true;
}

if (length == 6 && strncmp(version, "latest", length) == 0) {
options->version = PM_OPTIONS_VERSION_LATEST;
return true;
}
if (strncmp(version, "3.4.0", length) == 0) {
options->version = PM_OPTIONS_VERSION_LATEST;
return true;
}

return false;
case 6:
assert(version != NULL);

return false;
if (strncmp(version, "latest", length) == 0) {
options->version = PM_OPTIONS_VERSION_LATEST;
return true;
}

return false;
default:
return false;
}
}

// For some reason, GCC analyzer thinks we're leaking allocated scopes and
Expand Down
4 changes: 4 additions & 0 deletions prism/util/pm_integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ karatsuba_multiply(pm_integer_t *destination, pm_integer_t *left, pm_integer_t *

size_t length = left_length + right_length;
uint32_t *values = (uint32_t*) xcalloc(length, sizeof(uint32_t));

assert(z0.values != NULL);
memcpy(values, z0.values, sizeof(uint32_t) * z0.length);

assert(z2.values != NULL);
memcpy(values + 2 * half, z2.values, sizeof(uint32_t) * z2.length);

uint32_t carry = 0;
Expand Down

0 comments on commit f34409b

Please sign in to comment.