Skip to content

Commit d4f20a1

Browse files
committed
Fix signedness mismatches in string processing code
1 parent 6120564 commit d4f20a1

File tree

10 files changed

+25
-25
lines changed

10 files changed

+25
-25
lines changed

src/strings/decode_stream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void MVM_string_decodestream_discard_to(MVMThreadContext *tc, MVMDecodeStream *d
113113
#define RUN_DECODE_NOTHING_DECODED 0
114114
#define RUN_DECODE_STOPPER_NOT_REACHED 1
115115
#define RUN_DECODE_STOPPER_REACHED 2
116-
static MVMuint32 run_decode(MVMThreadContext *tc, MVMDecodeStream *ds, const MVMint32 *stopper_chars, MVMDecodeStreamSeparators *sep_spec, MVMint32 eof) {
116+
static MVMuint32 run_decode(MVMThreadContext *tc, MVMDecodeStream *ds, const MVMuint32 *stopper_chars, MVMDecodeStreamSeparators *sep_spec, MVMint32 eof) {
117117
MVMDecodeStreamChars *prev_chars_tail = ds->chars_tail;
118118
MVMuint32 reached_stopper;
119119
switch (ds->encoding) {
@@ -277,7 +277,7 @@ static MVMString * take_chars(MVMThreadContext *tc, MVMDecodeStream *ds, MVMint3
277277
}
278278
MVMString * MVM_string_decodestream_get_chars(MVMThreadContext *tc, MVMDecodeStream *ds,
279279
MVMint32 chars, MVMint64 eof) {
280-
MVMint32 missing;
280+
MVMuint32 missing;
281281

282282
/* If we request nothing, give empty string. */
283283
if (chars == 0)

src/strings/nfg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ MVMGrapheme32 MVM_nfg_crlf_grapheme(MVMThreadContext *tc) {
270270
* safe point. */
271271
MVMNFGSynthetic * MVM_nfg_get_synthetic_info(MVMThreadContext *tc, MVMGrapheme32 synth) {
272272
MVMNFGState *nfg = tc->instance->nfg;
273-
MVMint32 synth_idx = -synth - 1;
273+
MVMuint32 synth_idx = -synth - 1;
274274
if (synth >= 0)
275275
MVM_oops(tc, "MVM_nfg_get_synthetic_info illegally called on a non-synthetic codepoint.\nRequested codepoint %i.", synth);
276276
if (synth_idx >= nfg->num_synthetics)
@@ -475,7 +475,7 @@ void MVM_nfg_init(MVMThreadContext *tc) {
475475
* to a VM instance. */
476476
void MVM_nfg_destroy(MVMThreadContext *tc) {
477477
MVMNFGState *nfg = tc->instance->nfg;
478-
MVMint32 i;
478+
MVMuint32 i;
479479

480480
/* Free all synthetics. */
481481
if (nfg->synthetics) {

src/strings/nfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct MVMNFGState {
1818
uv_mutex_t update_mutex;
1919

2020
/* Number of synthetics we have. */
21-
MVMint32 num_synthetics;
21+
MVMuint32 num_synthetics;
2222

2323
/* Cached CRLF grapheme index, since we need it so often. */
2424
MVMGrapheme32 crlf_grapheme;

src/strings/ops.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static void iterate_gi_into_string(MVMThreadContext *tc, MVMGraphemeIter *gi, MV
355355
graphs_so_far += graphs_this_strand; \
356356
} \
357357
else { \
358-
int j = 0; \
358+
MVMuint32 j = 0; \
359359
for (; j <= orig->body.storage.strands[i].repetitions; j++) { \
360360
memcpy(graphs_so_far + result->body.storage.BLOB_TYPE, \
361361
orig->body.storage.strands[i].blob_string->body.storage.BLOB_TYPE + orig->body.storage.strands[i].start, \
@@ -842,7 +842,7 @@ static MVMuint16 final_strand_match_with_repetition_count(MVMThreadContext *tc,
842842
/* Append one string to another. */
843843
MVMString * MVM_string_concatenate(MVMThreadContext *tc, MVMString *a, MVMString *b) {
844844
MVMString *result = NULL, *renormalized_section = NULL;
845-
int renormalized_section_graphs = 0, consumed_a = 0, consumed_b = 0;
845+
MVMuint32 renormalized_section_graphs = 0, consumed_a = 0, consumed_b = 0;
846846
MVMuint32 agraphs, bgraphs;
847847
MVMuint64 total_graphs;
848848
int lost_strands = 0;
@@ -1620,7 +1620,7 @@ static MVMString * do_case_change(MVMThreadContext *tc, MVMString *s, MVMint32 t
16201620
}
16211621
else {
16221622
MVMGrapheme32 *transformed;
1623-
MVMint32 num_transformed = MVM_nfg_get_case_change(tc, g, type, &transformed);
1623+
MVMuint32 num_transformed = MVM_nfg_get_case_change(tc, g, type, &transformed);
16241624
if (num_transformed == 0) {
16251625
result_buf[i++] = g;
16261626
}
@@ -1874,7 +1874,7 @@ MVMObject * MVM_string_split(MVMThreadContext *tc, MVMString *separator, MVMStri
18741874
/* XXX make this use the dual-traverse iterator, but such that it
18751875
can reset the index of what it's comparing... <!> */
18761876
index = MVM_string_index(tc, input, separator, start);
1877-
length = sep_length ? (index == -1 ? end : index) - start : 1;
1877+
length = sep_length ? (index == (MVMStringIndex)-1 ? end : index) - start : 1;
18781878
if (0 < length || (sep_length && length == 0)) {
18791879
portion = MVM_string_substring(tc, input, start, length);
18801880
MVMROOT(tc, portion, {

src/strings/unicode_db.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75045,7 +75045,7 @@ static const char *bogus = "<BOGUS>"; /* only for table too short; return null s
7504575045
static const char* MVM_unicode_get_property_str(MVMThreadContext *tc, MVMint64 codepoint, MVMint64 property_code) {
7504675046
MVMuint32 switch_val = (MVMuint32)property_code;
7504775047
MVMint32 result_val = 0; /* we'll never have negatives, but so */
75048-
MVMuint32 codepoint_row;
75048+
MVMint32 codepoint_row;
7504975049
MVMuint16 bitfield_row = 0;
7505075050

7505175051
if (switch_val == MVM_UNICODE_PROPERTY_BLOCK) {
@@ -75167,7 +75167,7 @@ static const char* MVM_unicode_get_property_str(MVMThreadContext *tc, MVMint64 c
7516775167

7516875168
static MVMint32 MVM_unicode_get_property_int(MVMThreadContext *tc, MVMint64 codepoint, MVMint64 property_code) {
7516975169
MVMint32 result_val = 0; /* we'll never have negatives, but so */
75170-
MVMuint32 codepoint_row = MVM_codepoint_to_row_index(tc, codepoint);
75170+
MVMint32 codepoint_row = MVM_codepoint_to_row_index(tc, codepoint);
7517175171
MVMuint16 bitfield_row;
7517275172
/* If codepoint is not found in bitfield rows */
7517375173
if (codepoint_row == -1) {

src/strings/unicode_ops.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ MVMGrapheme32 MVM_unicode_lookup_by_name(MVMThreadContext *tc, MVMString *name)
700700
};
701701
int i;
702702
for (i = 0; i < prefixes_len; i++) {
703-
int str_len = strlen(prefixes[i]);
703+
size_t str_len = strlen(prefixes[i]);
704704
if (cname_len <= str_len)
705705
continue;
706706
/* Make sure to catch conditions which strtoll is ok with but we
@@ -713,7 +713,7 @@ MVMGrapheme32 MVM_unicode_lookup_by_name(MVMThreadContext *tc, MVMString *name)
713713
if (!strncmp(cname, prefixes[i], str_len)) {
714714
char *reject = NULL;
715715
MVMint64 rtrn = strtol(cname + strlen(prefixes[i]), &reject, 16);
716-
if (prefixes[i][0] == '<' && *reject == '>' && reject - cname + 1 == cname_len) {
716+
if (prefixes[i][0] == '<' && *reject == '>' && (size_t)(reject - cname + 1) == cname_len) {
717717
MVM_free(cname);
718718
return rtrn;
719719
}
@@ -752,7 +752,7 @@ MVMString * MVM_unicode_get_name(MVMThreadContext *tc, MVMint64 codepoint) {
752752
name_len = strlen(name);
753753
/* Look up name. */
754754
else {
755-
MVMuint32 codepoint_row = MVM_codepoint_to_row_index(tc, codepoint);
755+
MVMint32 codepoint_row = MVM_codepoint_to_row_index(tc, codepoint);
756756
if (codepoint_row != -1) {
757757
name = codepoint_names[codepoint_row];
758758
if (!name) {

src/strings/utf8_c8.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static unsigned classify(MVMCodepoint cp) {
8686
return 0;
8787
}
8888

89-
static MVMint32 utf8_encode(MVMuint8 *bp, MVMCodepoint cp) {
89+
static MVMuint32 utf8_encode(MVMuint8 *bp, MVMCodepoint cp) {
9090
unsigned cc = classify(cp);
9191

9292
if (!(cc & (CP_CHAR | CP_NONCHAR)))
@@ -194,7 +194,7 @@ typedef struct {
194194

195195
/* Bad bytes from an earlier buffer, for the sake of streaming decode. */
196196
MVMuint8 prev_bad_bytes[4];
197-
MVMint32 num_prev_bad_bytes;
197+
MVMuint32 num_prev_bad_bytes;
198198
} DecodeState;
199199

200200
/* Appends a single grapheme to the buffer if it will not cause a mismatch
@@ -241,7 +241,7 @@ static int append_grapheme(MVMThreadContext *tc, DecodeState *state, MVMGrapheme
241241
for (i = state->orig_codes_unnormalized; i < state->orig_codes_pos; i++) {
242242
MVMCodepoint to_encode = state->orig_codes[i];
243243
MVMuint8 encoded[4];
244-
MVMint32 bytes = utf8_encode(encoded, to_encode);
244+
MVMuint32 bytes = utf8_encode(encoded, to_encode);
245245
for (j = 0; j < bytes; j++)
246246
state->result[state->result_pos++] = synthetic_for(tc, encoded[j]);
247247
}
@@ -417,7 +417,7 @@ MVMString * MVM_string_utf8_c8_decode(MVMThreadContext *tc, const MVMObject *res
417417
/* Decodes using a decodestream. Decodes as far as it can with the input
418418
* buffers, or until a stopper is reached. */
419419
MVMuint32 MVM_string_utf8_c8_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds,
420-
const MVMint32 *stopper_chars,
420+
const MVMuint32 *stopper_chars,
421421
MVMDecodeStreamSeparators *seps,
422422
MVMint32 eof) {
423423
/* Local state for decode loop. */
@@ -467,7 +467,7 @@ MVMuint32 MVM_string_utf8_c8_decodestream(MVMThreadContext *tc, MVMDecodeStream
467467
reached_stopper = 0;
468468
while (cur_bytes && !reached_stopper) {
469469
/* Set up decode state for this buffer. */
470-
MVMint32 bytes = cur_bytes->length;
470+
MVMuint32 bytes = cur_bytes->length;
471471
/* Space for graphemes we have + 1 grapheme we receive from last buffer */
472472
state.result = MVM_malloc((bytes + 1) * sizeof(MVMGrapheme32));
473473
state.orig_codes = MVM_realloc(state.orig_codes,
@@ -577,7 +577,7 @@ MVMuint32 MVM_string_utf8_c8_decodestream(MVMThreadContext *tc, MVMDecodeStream
577577
/* If there were bytes we didn't accept, hold on to them in case we
578578
* need to emit them as bad bytes. */
579579
if (state.unaccepted_start != state.cur_byte && cur_bytes->next) {
580-
int i;
580+
size_t i;
581581
for (i = state.unaccepted_start; i < state.cur_byte; i++)
582582
state.prev_bad_bytes[state.num_prev_bad_bytes++] = state.utf8[i];
583583
}
@@ -609,7 +609,7 @@ MVMuint32 MVM_string_utf8_c8_decodestream(MVMThreadContext *tc, MVMDecodeStream
609609
static void emit_cp(MVMThreadContext *tc, MVMCodepoint cp, MVMuint8 **result,
610610
size_t *result_pos, size_t *result_limit,
611611
MVMuint8 *repl_bytes, MVMuint64 repl_length) {
612-
MVMint32 bytes;
612+
MVMuint32 bytes;
613613
if (*result_pos >= *result_limit) {
614614
*result_limit *= 2;
615615
*result = MVM_realloc(*result, *result_limit + 4);

src/strings/utf8_c8.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
MVM_PUBLIC MVMString * MVM_string_utf8_c8_decode(MVMThreadContext *tc, const MVMObject *result_type, const char *utf8, size_t bytes);
2-
MVM_PUBLIC MVMuint32 MVM_string_utf8_c8_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds, const MVMint32 *stopper_chars, MVMDecodeStreamSeparators *seps, MVMint32 eof);
2+
MVM_PUBLIC MVMuint32 MVM_string_utf8_c8_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds, const MVMuint32 *stopper_chars, MVMDecodeStreamSeparators *seps, MVMint32 eof);
33
MVM_PUBLIC char * MVM_string_utf8_c8_encode_substr(MVMThreadContext *tc,
44
MVMString *str, MVMuint64 *output_size, MVMint64 start, MVMint64 length, MVMString *replacement);
55
MVM_PUBLIC char * MVM_string_utf8_c8_encode(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size);

src/strings/windows1252.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ MVMString * MVM_string_windows125X_decode(MVMThreadContext *tc,
501501
/* Since things we are decoding always fit into Unicode, if we are
502502
* using a replacement, it won't get used unless we use strict */
503503
if (replacement && MVM_ENCODING_CONFIG_STRICT(config)) {
504-
int i = 0;
504+
MVMStringIndex i = 0;
505505
/* Only triggered if repl_length > 1. Copies all but the last
506506
* grapheme in the replacement string */
507507
if (1 < repl_length) {

tools/ucd2c.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ sub emit_property_value_lookup {
911911
912912
static MVMint32 MVM_unicode_get_property_int(MVMThreadContext *tc, MVMint64 codepoint, MVMint64 property_code) {
913913
MVMint32 result_val = 0; /* we'll never have negatives, but so */
914-
MVMuint32 codepoint_row = MVM_codepoint_to_row_index(tc, codepoint);
914+
MVMint32 codepoint_row = MVM_codepoint_to_row_index(tc, codepoint);
915915
MVMuint16 bitfield_row;
916916
/* If codepoint is not found in bitfield rows */
917917
if (codepoint_row == -1) {
@@ -935,7 +935,7 @@ END
935935
static const char* MVM_unicode_get_property_str(MVMThreadContext *tc, MVMint64 codepoint, MVMint64 property_code) {
936936
MVMuint32 switch_val = (MVMuint32)property_code;
937937
MVMint32 result_val = 0; /* we'll never have negatives, but so */
938-
MVMuint32 codepoint_row;
938+
MVMint32 codepoint_row;
939939
MVMuint16 bitfield_row = 0;
940940
941941
if (switch_val == MVM_UNICODE_PROPERTY_BLOCK) {

0 commit comments

Comments
 (0)