Hacker News new | ask | show | jobs
by jpollock 1260 days ago
I asked ChatGPT to decode a Diameter header in Java (RFC 6733 Section 3).

It supplied this :

    // Parse the Diameter header
    ByteBuffer buffer = ByteBuffer.wrap(message);
    int version = buffer.get() & 0xff;
    int flags = buffer.get() & 0xff;
    int length = buffer.getShort() & 0xffff;
First problem, it's version, length, flags. Second problem, length is 24 bits, not 16. Third, 24 bits unsigned won't fit in a Java int (which is signed). Then there is the extra masking, which isn't a bug but is (I'm reasonably sure) unnecessary.

That's 3 sneaky bugs in 4 lines of code, and it didn't even try to parse the rest of the header.

I'm impressed that it produces _anything_, but it's dangerous to trust.

ChatGPT is as reliable a source as any friend in a pub after 3 beers. It is definite in its answer, convincing with its phrasing and more than likely misremembering something it overheard on the radio while driving to work.

When I tried re-prompting, it produced more complicated, just as incorrect code.