demo: better ndraw
This commit is contained in:
parent
1fc7d20dab
commit
00a1bcd657
12
demo/main.c
12
demo/main.c
@ -5,13 +5,23 @@ int unit_tests(void);
|
||||
|
||||
void ndraw(mp_int* a, const char* name)
|
||||
{
|
||||
char buf[16000]; /* TODO: buffer might overflow! */
|
||||
char *buf;
|
||||
int size;
|
||||
|
||||
mp_radix_size(a, 10, &size);
|
||||
buf = malloc((size_t) size);
|
||||
if (buf == NULL) {
|
||||
fprintf(stderr, "\nndraw: malloc(%d) failed\n", size);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("%s: ", name);
|
||||
mp_toradix(a, buf, 10);
|
||||
printf("%s\n", buf);
|
||||
mp_toradix(a, buf, 16);
|
||||
printf("0x%s\n", buf);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
Loading…
Reference in New Issue
Block a user