summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-04-16 21:15:12 -0400
committergit <[email protected]>2024-04-17 01:15:21 +0000
commitf34409bf8782481deabec6c577abd66373134af9 (patch)
tree4e63c3eb9864d290103c5eb2f4ceeb7ec14ffa13
parentd6debba817da921d8bc9a3fdb6b4bcbe3d7b0859 (diff)
[ruby/prism] Fix up more clang-analyzer failures
https://github.com/ruby/prism/commit/f9a1abbc64
-rw-r--r--prism/options.c49
-rw-r--r--prism/util/pm_integer.c4
2 files changed, 34 insertions, 19 deletions
diff --git a/prism/options.c b/prism/options.c
index 2854b765b9..4d0d6dbc49 100644
--- a/prism/options.c
+++ b/prism/options.c
@@ -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
diff --git a/prism/util/pm_integer.c b/prism/util/pm_integer.c
index 50210f0cb1..0739662e98 100644
--- a/prism/util/pm_integer.c
+++ b/prism/util/pm_integer.c
@@ -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;