kokke / kokke/tiny-bignum-c

bignum_from_string not works on odd nbytes

Open
#25 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
474
Forks
90
PR merge metrics
No merged PRs in 30d

Description

`
char buffer[500];
struct bn a, b, c;

bignum_from_string(&a, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe", 64);
bignum_to_string(&a, buffer, 500);
printf("%s\n", buffer);

bignum_from_int(&b, 3);

bignum_add(&a, &b, &c);
bignum_to_string(&c, buffer, 500);
printf("%s\n", buffer);
`

length of "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" is 63
if I change 64 to 63 and comment out
`
// require((nbytes & 1) == 0, "string format must be in hex -> equal number of bytes");
// require((nbytes % (sizeof(DTYPE) * 2)) == 0, "string length must be a multiple of (sizeof(DTYPE) * 2) characters");
`

that code works correct

PR created: https://github.com/kokke/tiny-bignum-c/pull/26

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the bignum_from_string example in the issue and inspect the validation checks shown there, then compare the already-linked PR #26. Done means the 63-character hexadecimal input is handled correctly and the subsequent conversion and addition produce the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.