ASCII->POLY: avoid trailing junk data
This commit is contained in:
parent
bdc3aad651
commit
27b20f97b7
|
@ -129,13 +129,19 @@ get_bin_arr_to_ascii(char *binary_rep)
|
||||||
/* we are one over the top */
|
/* we are one over the top */
|
||||||
i--;
|
i--;
|
||||||
|
|
||||||
int_string = ntru_malloc(CHAR_SIZE * i);
|
int_string = ntru_malloc(CHAR_SIZE * (i + 1));
|
||||||
|
|
||||||
for (uint32_t j = 0; j < i; j++)
|
for (uint32_t j = 0; j < i; j++)
|
||||||
int_string[j] = (char) int_arr[j];
|
int_string[j] = (char) int_arr[j];
|
||||||
|
|
||||||
|
/* make sure this is always terminated, because
|
||||||
|
* of following strlen call */
|
||||||
|
int_string[i] = '\0';
|
||||||
|
|
||||||
result->ptr = int_string;
|
result->ptr = int_string;
|
||||||
result->len = i;
|
/* we can't use "i" here as length, because we
|
||||||
|
* want to get rid of trailing null-bytes */
|
||||||
|
result->len = strlen(int_string);
|
||||||
|
|
||||||
free(int_arr);
|
free(int_arr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue