Skip to content

Commit

Permalink
Merge pull request #1399 from MasterDuke17/fix_some_stuff_clang_stati…
Browse files Browse the repository at this point in the history
…c_analyzer_found
  • Loading branch information
MasterDuke17 committed Dec 20, 2020
2 parents 9320005 + e8d6366 commit 6bf54d7
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 26 deletions.
20 changes: 13 additions & 7 deletions src/6model/reprs/P6opaque.c
Expand Up @@ -843,9 +843,10 @@ static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info_hash) {
MVM_free_null(name_map->names);
MVM_free_null(name_map->slots);
}
MVMint16 unbox_int_slot = repr_data->unbox_int_slot;
free_repr_data(repr_data);
MVM_exception_throw_adhoc(tc,
"While composing %s: Duplicate box_target for native int: attributes %d and %"PRId64, MVM_6model_get_stable_debug_name(tc, st), repr_data->unbox_int_slot, i);
"While composing %s: Duplicate box_target for native int: attributes %d and %"PRId64, MVM_6model_get_stable_debug_name(tc, st), unbox_int_slot, i);
}
repr_data->unbox_int_slot = cur_slot;
break;
Expand All @@ -855,9 +856,10 @@ static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info_hash) {
MVM_free_null(name_map->names);
MVM_free_null(name_map->slots);
}
MVMint16 unbox_num_slot = repr_data->unbox_num_slot;
free_repr_data(repr_data);
MVM_exception_throw_adhoc(tc,
"While composing %s: Duplicate box_target for native num: attributes %d and %"PRId64, MVM_6model_get_stable_debug_name(tc, st), repr_data->unbox_num_slot, i);
"While composing %s: Duplicate box_target for native num: attributes %d and %"PRId64, MVM_6model_get_stable_debug_name(tc, st), unbox_num_slot, i);
}
repr_data->unbox_num_slot = cur_slot;
break;
Expand All @@ -867,9 +869,10 @@ static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info_hash) {
MVM_free_null(name_map->names);
MVM_free_null(name_map->slots);
}
MVMint16 unbox_str_slot = repr_data->unbox_str_slot;
free_repr_data(repr_data);
MVM_exception_throw_adhoc(tc,
"While composing %s: Duplicate box_target for native str: attributes %d and %"PRId64, MVM_6model_get_stable_debug_name(tc, st), repr_data->unbox_str_slot, i);
"While composing %s: Duplicate box_target for native str: attributes %d and %"PRId64, MVM_6model_get_stable_debug_name(tc, st), unbox_str_slot, i);
}
repr_data->unbox_str_slot = cur_slot;
break;
Expand Down Expand Up @@ -910,9 +913,10 @@ static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info_hash) {
MVM_free_null(name_map->names);
MVM_free_null(name_map->slots);
}
MVMint16 pos_del_slot = repr_data->pos_del_slot;
free_repr_data(repr_data);
MVM_exception_throw_adhoc(tc,
"While composing %s: Duplicate positional delegate attributes: %d and %"PRId64"", MVM_6model_get_stable_debug_name(tc, st), repr_data->pos_del_slot, cur_slot);
"While composing %s: Duplicate positional delegate attributes: %d and %"PRId64"", MVM_6model_get_stable_debug_name(tc, st), pos_del_slot, cur_slot);
}
if (unboxed_type == MVM_STORAGE_SPEC_BP_NONE)
repr_data->pos_del_slot = cur_slot;
Expand All @@ -932,9 +936,10 @@ static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info_hash) {
MVM_free_null(name_map->names);
MVM_free_null(name_map->slots);
}
MVMint16 pos_del_slot = repr_data->pos_del_slot;
free_repr_data(repr_data);
MVM_exception_throw_adhoc(tc,
"While composing %s: Duplicate associative delegate attributes: %d and %"PRId64, MVM_6model_get_stable_debug_name(tc, st), repr_data->pos_del_slot, cur_slot);
"While composing %s: Duplicate associative delegate attributes: %d and %"PRId64, MVM_6model_get_stable_debug_name(tc, st), pos_del_slot, cur_slot);
}
if (unboxed_type == MVM_STORAGE_SPEC_BP_NONE)
repr_data->ass_del_slot = cur_slot;
Expand Down Expand Up @@ -1127,14 +1132,15 @@ static void deserialize_repr_data(MVMThreadContext *tc, MVMSTable *st, MVMSerial
MVMuint16 repr_id = MVM_serialization_read_int(tc, reader);
MVMuint16 slot = MVM_serialization_read_int(tc, reader);
if (slot > repr_data->num_attributes) {
MVMuint16 num_attributes = repr_data->num_attributes;
free_repr_data(repr_data);
MVM_exception_throw_adhoc(tc, "Serialization error: P6opaque's unbox slot out of range (slot %d > %d attributes).", slot, repr_data->num_attributes);
MVM_exception_throw_adhoc(tc, "Serialization error: P6opaque's unbox slot out of range (slot %d > %d attributes).", slot, num_attributes);
}
if (repr_id < MVM_REPR_MAX_COUNT)
repr_data->unbox_slots[repr_id] = slot;
else {
free_repr_data(repr_data);
MVM_exception_throw_adhoc(tc, "Serialization error: P6opaque's unbox slot repr id out of range.");
MVM_exception_throw_adhoc(tc, "Serialization error: P6opaque's unbox slot repr id out of range (repr id %d >= %d).", repr_id, MVM_REPR_MAX_COUNT);
}
}
} else {
Expand Down
1 change: 0 additions & 1 deletion src/6model/serialization.c
Expand Up @@ -2208,7 +2208,6 @@ static void resolve_dependencies(MVMThreadContext *tc, MVMSerializationReader *r
else {
cdesc = "<unknown>";
}
if (!desc) desc = handle;
fail_deserialize(tc, waste, reader,
"Missing or wrong version of dependency '%s' (from '%s')",
cname,
Expand Down
2 changes: 1 addition & 1 deletion src/core/threadcontext.c
Expand Up @@ -52,7 +52,7 @@ MVMThreadContext * MVM_tc_create(MVMThreadContext *parent, MVMInstance *instance
}
MVM_free(tc->temp_bigints[i]);
MVM_tc_destroy(tc);
MVM_exception_throw_adhoc(tc, "Error creating a temporary big integer: %s", mp_error_to_string(err));
MVM_exception_throw_adhoc(parent, "Error creating a temporary big integer: %s", mp_error_to_string(err));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/debug/debugserver.c
Expand Up @@ -934,8 +934,8 @@ static void send_thread_info(MVMThreadContext *dtc, cmp_ctx_t *ctx, request_data
if (threadname != NULL && strlen(threadname)) {
cmp_write_str(ctx, "name", 4);
cmp_write_str(ctx, threadname, strlen(threadname));
MVM_free(threadname);
}
MVM_free(threadname);

cur_thread = cur_thread->body.next;
}
Expand Down
5 changes: 1 addition & 4 deletions src/instrument/line_coverage.c
Expand Up @@ -26,7 +26,6 @@ static void instrument_graph_with_breakpoints(MVMThreadContext *tc, MVMSpeshGrap
filename_string_index = bbba->filename_string_heap_index;
MVM_free(bbba);
} else {
line_number = -1;
bb = bb->linear_next;
continue;
}
Expand Down Expand Up @@ -147,7 +146,6 @@ static void instrument_graph(MVMThreadContext *tc, MVMSpeshGraph *g) {
filename_string_index = bbba->filename_string_heap_index;
MVM_free(bbba);
} else {
line_number = -1;
bb = bb->linear_next;
continue;
}
Expand Down Expand Up @@ -308,12 +306,11 @@ void MVM_line_coverage_report(MVMThreadContext *tc, MVMString *filename, MVMuint
if (tc->instance->coverage_control == 2 || (!tc->instance->coverage_control && cache[cache_slot] == 0)) {
char *encoded_filename;
char composed_line[256];
size_t length;

cache[cache_slot] = 1;

encoded_filename = MVM_string_utf8_encode_C_string(tc, filename);
if ((length = snprintf(composed_line, 255, "HIT %s %d\n", encoded_filename, line_number)) > 0) {
if (snprintf(composed_line, 255, "HIT %s %d\n", encoded_filename, line_number) > 0) {
fputs(composed_line, tc->instance->coverage_log_fh);
}
MVM_free(encoded_filename);
Expand Down
3 changes: 1 addition & 2 deletions src/platform/random.c
Expand Up @@ -71,8 +71,7 @@
#include <unistd.h>
MVMint32 MVM_getrandom_urandom (MVMThreadContext *tc, void *out, size_t size) {
int fd = MVM_platform_open("/dev/urandom", O_RDONLY);
ssize_t num_read = 0;
if (fd < 0 || (num_read = read(fd, out, size) <= 0)) {
if (fd < 0 || read(fd, out, size) <= 0) {
if (fd) close(fd);
/* If using /dev/urandom fails (maybe we're in a chroot), on BSD's
* use arc4random, which is likely seeded from the system's random
Expand Down
11 changes: 10 additions & 1 deletion src/profiler/heapsnapshot.c
Expand Up @@ -1001,8 +1001,10 @@ void string_heap_to_filehandle_ver3(MVMThreadContext *tc, MVMHeapSnapshotCollect
i++;
}

if (result_buffer_insert_pos == result_buffer)
if (result_buffer_insert_pos == result_buffer) {
MVM_free(result_buffer_insert_pos);
return;
}

size_position = ftell(fh);
fwrite(&typename, sizeof(char), 8, fh);
Expand All @@ -1012,6 +1014,7 @@ void string_heap_to_filehandle_ver3(MVMThreadContext *tc, MVMHeapSnapshotCollect
cstream = ZSTD_createCStream();

if (ZSTD_isError(return_value = ZSTD_initCStream(cstream, ZSTD_COMPRESSION_VALUE))) {
MVM_free(result_buffer);
MVM_panic(1, "ZSTD compression error in heap snapshot: %s", ZSTD_getErrorName(return_value));
}

Expand All @@ -1033,6 +1036,8 @@ void string_heap_to_filehandle_ver3(MVMThreadContext *tc, MVMHeapSnapshotCollect
return_value = ZSTD_compressStream(cstream, &outbuf, &inbuf);

if (ZSTD_isError(return_value)) {
MVM_free(outbuf.dst);
MVM_free(result_buffer);
MVM_panic(1, "Error compressing heap snapshot data: %s", ZSTD_getErrorName(return_value));
}

Expand All @@ -1059,6 +1064,8 @@ void string_heap_to_filehandle_ver3(MVMThreadContext *tc, MVMHeapSnapshotCollect


if (ZSTD_isError(return_value)) {
MVM_free(outbuf.dst);
MVM_free(result_buffer);
MVM_panic(1, "Error compressing heap snapshot data: %s", ZSTD_getErrorName(return_value));
}

Expand Down Expand Up @@ -1757,6 +1764,7 @@ static void filemeta_to_filehandle_ver3(MVMThreadContext *tc, MVMHeapSnapshotCol
fwrite(&size, sizeof(MVMuint64), 1, fh);

fputs(metadata, fh);
MVM_free(metadata);
fputc(0, fh);

end_position = ftell(fh);
Expand Down Expand Up @@ -1808,6 +1816,7 @@ static void snapmeta_to_filehandle_ver3(MVMThreadContext *tc, MVMHeapSnapshotCol
fwrite(&size, sizeof(MVMuint64), 1, fh);

fputs(metadata, fh);
MVM_free(metadata);
fputc(0, fh);

end_position = ftell(fh);
Expand Down
2 changes: 0 additions & 2 deletions src/spesh/optimize.c
Expand Up @@ -1149,8 +1149,6 @@ static void optimize_string_equality(MVMThreadContext *tc, MVMSpeshGraph *g, MVM
MVMSpeshFacts *b_facts = MVM_spesh_get_facts(tc, g, ins->operands[2]);
MVMuint8 was_eq = 0;

return;

if (ins->info->opcode == MVM_OP_eq_s)
was_eq = 1;

Expand Down
6 changes: 0 additions & 6 deletions src/strings/ops.c
Expand Up @@ -2329,9 +2329,6 @@ MVMString * MVM_string_flip(MVMThreadContext *tc, MVMString *s) {
while (spos_l < s->body.num_graphs)
rbuffer[--rpos_l] = s->body.storage.blob_8[spos_l++];

spos += sgraphs - spos;
rpos -= sgraphs - spos;

MVMROOT(tc, s, {
res = (MVMString *)MVM_repr_alloc_init(tc, tc->instance->VMString);
});
Expand All @@ -2348,9 +2345,6 @@ MVMString * MVM_string_flip(MVMThreadContext *tc, MVMString *s) {
MVM_VECTORIZE_LOOP
while (spos_l < s->body.num_graphs)
rbuffer[--rpos_l] = s->body.storage.blob_32[spos_l++];

spos += sgraphs - spos;
rpos -= sgraphs - spos;
}
else
for (; spos < sgraphs; spos++)
Expand Down
1 change: 0 additions & 1 deletion src/strings/utf8_c8.c
Expand Up @@ -426,7 +426,6 @@ MVMuint32 MVM_string_utf8_c8_decodestream(MVMThreadContext *tc, MVMDecodeStream
/* If there's no buffers, we're done. */
if (!ds->bytes_head)
return 0;
last_accept_pos = ds->bytes_head_pos;

/* If we're asked for zero chars, also done. */
if (stopper_chars && *stopper_chars == 0)
Expand Down

0 comments on commit 6bf54d7

Please sign in to comment.