| ▲ | asveikau a day ago | |||||||
A bit of a code review (some details from the patch removed for clarity):
You don't actually need i here. i is the same as (q - password). It would be idiomatic C to simply rewrite the loop condition as: while (q < password+sizeof(password) && (*q = getchar()) != '\n'). To preserve your "goto error;" part, maybe you could do the overflow check when null terminating outside the loop. | ||||||||
| ▲ | shakna a day ago | parent [-] | |||||||
Isn't sizeof only standardised in C89? Wouldn't shock me if this form needs to be an rvalue. The author did try pointer arithmetic: > I initially attempted a fix using pointer arithmetic, but the 1973 C compiler didn’t like it, while it didn’t refuse the syntax, the code had no effect. | ||||||||
| ||||||||