First, when you read the following code:
6. The association between buggy lines vs non-buggy lines have to be able to focus on malloc() to give intPointer[] + data x sizeof() + for() usage of the intPointer array. All other lines will need to be deemphasized.The first question is immediately: data * sizeof() is not checked, and therefore may overflow the maximum size allowed for any malloc(). And that is a bug.
And if overflow into a small value, then now malloc() becomes NOT a bug, as malloc(SMALL) small value is OK.
But continuing further:
now the bug will resurface in intPointer[].
This show several properties needed for proper representation of programming to detect bugs:
1. range min/max: any input have a limit on both side.
2. range output: upon memory allocation, the values should be range-checked to determine validity.
3. properties propagation: as we analyze the logic flow above, we noticed that the bug situation turned from buggy to not buggy and then flow into another function to be buggy.
4. duality of outcome in two situation: that is a sign of logic error.
First outcome: data * sizeof() and followed by "for(i...<data;i++) =>> this will give one set of value, if there is no overflow. But if there is a overflow, then each of them will have different values.
5. If "data overflow" is never used as a programming method to derive values mathematically, then the existence of "overflow" should trigger an alert to error.
No comments:
Post a Comment