Fix a bug where the first charmap entry wasn't added correctly.

This commit is contained in:
stag019
2013-12-28 00:35:05 -05:00
parent c61c112218
commit 34656f9e5d

View File

@@ -75,6 +75,11 @@ charmap_Add(char *input, UBYTE output)
charmap = &globalCharmap; charmap = &globalCharmap;
} }
if(nPass == 2)
{
return charmap -> count;
}
if(charmap -> count > MAXCHARMAPS || strlen(input) > CHARMAPLENGTH) if(charmap -> count > MAXCHARMAPS || strlen(input) > CHARMAPLENGTH)
{ {
return -1; return -1;
@@ -84,7 +89,7 @@ charmap_Add(char *input, UBYTE output)
if(input_length > 1) if(input_length > 1)
{ {
i = 0; i = 0;
while(i < charmap -> count) while(i < charmap -> count + 1)
{ {
if(input_length > strlen(charmap -> input[i])) if(input_length > strlen(charmap -> input[i]))
{ {
@@ -97,7 +102,7 @@ charmap_Add(char *input, UBYTE output)
} }
i++; i++;
} }
while(i < charmap -> count) while(i < charmap -> count + 1)
{ {
memcpy(temp2i, charmap -> input[i], CHARMAPLENGTH + 1); memcpy(temp2i, charmap -> input[i], CHARMAPLENGTH + 1);
memcpy(charmap -> input[i], temp1i, CHARMAPLENGTH + 1); memcpy(charmap -> input[i], temp1i, CHARMAPLENGTH + 1);
@@ -107,13 +112,13 @@ charmap_Add(char *input, UBYTE output)
temp1o = temp2o; temp1o = temp2o;
i++; i++;
} }
memcpy(charmap -> input[charmap -> count], temp1i, CHARMAPLENGTH + 1); memcpy(charmap -> input[charmap -> count + 1], temp1i, CHARMAPLENGTH + 1);
charmap -> output[charmap -> count] = temp1o; charmap -> output[charmap -> count + 1] = temp1o;
} }
else else
{ {
memcpy(charmap -> input[charmap -> count - 1], input, CHARMAPLENGTH + 1); memcpy(charmap -> input[charmap -> count], input, CHARMAPLENGTH + 1);
charmap -> output[charmap -> count - 1] = output; charmap -> output[charmap -> count] = output;
} }
return ++charmap -> count; return ++charmap -> count;
} }