4 ms·
A = {'a','b','\0'}; B = {'a', 'b', '\0'}; safercopy(2, A, 2, B); A = {'a','b'}; B = {'a', 'b', '\0'}; safercopy(2, A, 2, B); A = {'a','b','\0'}; B = {
by judofyr 14y ago
A = {'a','b','\0'}; B = {'a', 'b', '\0'}; safercopy(2, A, 2, B);
A = {'a','b'}; B = {'a', 'b', '\0'}; safercopy(2, A, 2, B);
A = {'a','b','\0'}; B = {'a', 'b'}; safercopy(2, A, 2, B);
A = {'a','b'}; B = {'a', 'b'}; safercopy(2, A, 2, B);
This analysis only tries different values of A and B, not the lengths. A proper analysis of "for what values does it fail" should include all parameters. What happens if you do `safercopy(3, A, 2, B)` or `safercopy(3, A, 3, B)`?
- tcarney 14y agoExactly what I noticed. The "safer" function relies on the length arguments being correct, just as the copy function relied on the strings being null-terminated. The safer function is more explicit so less prone to error, but both rely on the programmer doing the right thing, which is what he was trying to avoid...
- yxhuvud 14y agoThe good part is that valgrind will hopefully find that it read outside bounds immediately, as opposed to code depending on correct string termination which will work with correct test cases.