3 ms·
Just for reference, copied this snippet in GPT-4, it generated this answer in 1,5 seconds: > The issue in this code is related to memory access. The line data[
by golergka 3y ago
Just for reference, copied this snippet in GPT-4, it generated this answer in 1,5 seconds:
> The issue in this code is related to memory access. The line data[n] = '\0'; should be (data)[n] = '\0';.
And then went on to generate corrected code and this explanation:
> The original expression, data[n], first applies the array subscript operation, which is equivalent to (data + n), and then tries to dereference the resulting pointer, which is not the intention here. This will likely lead to a segmentation fault because data is a pointer to pointer, and data[n] will try to access memory that has not been allocated.
> The corrected expression, (*data)[n], first dereferences data to get the allocated char array, and then applies the array subscript operation to set the null terminator at the correct location.
- ChatGTP 3y agoJust wondering if you think this type of bug hasn't been covered at least 50x in many online forums, I'd be very surprised? I'm not trying to say this isn't impressive, but seems fairly obvious and more like something a linter / analyzer would pickup ?
- almog 3y agoEven if this isn't based on similar questions that can be found online, a bug in existing systems usually wouldn't introduce itself by framing an isolated section of code. More often than not it'd be through indirection or a side effect that covers a larger execution path.
- deleted 3y ago[deleted]
- golergka 3y agoTo an experienced C developer who works with the language constantly — probably. I'm not one, so I wouldn't know. I've found GPT to be much more helpful when you're working with technologies you'r not as familiar or up to date with.
- thfuran 3y agoWhat does it do if you correct the bug and then ask it what the bug is?