Can ChatGPT debug my code? Can it write better code?
Everyone’s talking about it, so why should I not add something too.
Interview question
ChatGPT is pretty amazing. I asked it an interview question, and it just plain solved it. Well, there was one real world imperfection. I asked it to fix that problem, and then it went off the rails. The more I hinted, the worse the code got.
I won’t give the details here, because I want to keep using the question / topic.
Finding bugs
So I wondered if it could find bugs. First an easy one:
Q:
What's the problem with this C++ code:
int* foo() {
auto ret = new int;
int r2 = *ret * 2;
return &r2;
}
A:
There are several problems with the code you provided:
1. The function foo is returning a pointer to a local variable r2,
which is not safe because the memory for r2 is deallocated when the
function returns. This can cause undefined behavior when you try to
access the returned pointer after the function has returned.
2. The function foo is allocating memory for an integer with new int,
but it is not deallocating that memory before the function
returns. This can lead to a Continue reading




s OpenSLP service: CVE-2019-5544 and CVE-2020-3992.











