Thread: Alter strings that don't belong to the application
I've been looking into the code of psql to fix a problem with charsets and noticed that psql changes the strings it gets back from functions like PQfname() and PQgetvalue(). I can't find in the docs anything that says that it is okay to alter the returned string. It works since it's allocated and stored in the PGresult (I assume), so it's local to one result. But it's not obvious to me just looking at the API that it's allowed. Or should I read that the return value is "char *" and not "const char *" as it's okay to alter it? -- /Dennis
Dennis Björklund <db@zigo.dhs.org> writes: > I've been looking into the code of psql to fix a problem with charsets and > noticed that psql changes the strings it gets back from functions like > PQfname() and PQgetvalue(). I'd call that a bug in psql. Where do you see it happening exactly? > Or should I read that the return value is "char *" and not "const char *" > as it's okay to alter it? No, I think the return value ought to be treated as const char *. We're hesitant to actually declare it that way because we'd cause compile errors in many client applications that aren't being const-paranoid. But the app has no business modifying those values. regards, tom lane
On Thu, 12 Jun 2003, Tom Lane wrote: > I'd call that a bug in psql. Where do you see it happening exactly? It's the utf-8 validation function (mbvalidate) that removes characters that it does not understand. > No, I think the return value ought to be treated as const char *. > We're hesitant to actually declare it that way because we'd cause compile > errors in many client applications that aren't being const-paranoid. An easy solution is to add the const as a macro that can be turned off by those apps. ps. I'm being blacklisted by your email server. The reason I get back is that my letter come from a telia IP-number. Telia is the major ISP in Sweden with something like 80-90% of the market. I actually don't belong to those since I use another ISP (bostream), but I guess they got their adresses from telia or something. Well, not really a problem. I send everything to the list anyway. -- /Dennis
Dennis Björklund <db@zigo.dhs.org> writes: > On Thu, 12 Jun 2003, Tom Lane wrote: >> I'd call that a bug in psql. Where do you see it happening exactly? > It's the utf-8 validation function (mbvalidate) that removes characters > that it does not understand. I think the string ought to be copied first ... although that might create memory-leak problems. Could you take a look at fixing this, while you're in the area? > ps. I'm being blacklisted by your email server. I can whitelist you if you have a stable IP address --- is that a static or dynamic assignment? regards, tom lane
On Thu, 12 Jun 2003, Tom Lane wrote: > I think the string ought to be copied first ... although that might > create memory-leak problems. Could you take a look at fixing this, > while you're in the area? Sure. > I can whitelist you if you have a stable IP address --- is that a static > or dynamic assignment? It's static and I've had it for years. -- /Dennis