Skip to content

Commit

Permalink
Fix bitwise string and.
Browse files Browse the repository at this point in the history
Should take length of the shortest string.
  • Loading branch information
jnthn committed Dec 18, 2013
1 parent 006f6f6 commit 67d0815
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/strings/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,20 +1189,15 @@ MVMString * MVM_string_bitand(MVMThreadContext *tc, MVMString *a, MVMString *b)
MVMString *res = NULL;
MVMStringIndex alen = NUM_GRAPHS(a);
MVMStringIndex blen = NUM_GRAPHS(b);
MVMStringIndex sgraphs = (alen > blen ? alen : blen);
MVMStringIndex sgraphs = alen < blen ? alen : blen;
MVMCodepoint32 *buffer = malloc(sizeof(MVMCodepoint32) * sgraphs);
MVMStringIndex i, scanlen;

/* First, binary-and up to the length of the shortest string. */
scanlen = alen > blen ? blen : alen;
for (i = 0; i < scanlen; i++)
/* Binary-and up to the length of the shortest string. */
for (i = 0; i < sgraphs; i++)
buffer[i] = (MVM_string_get_codepoint_at_nocheck(tc, a, i)
& MVM_string_get_codepoint_at_nocheck(tc, b, i));

/* Second pass, fill with zeros. */
for (; i < sgraphs; i++)
buffer[i] = 0;

res = (MVMString *)MVM_repr_alloc_init(tc, tc->instance->VMString);
res->body.flags = MVM_STRING_TYPE_INT32;
res->body.graphs = sgraphs;
Expand Down

0 comments on commit 67d0815

Please sign in to comment.