Re: Errors/Warnings missing line numbers

Joel Richard <[email protected]>
Newsgroups gmane.comp.db.postgresql.dbdpg
Message-ID <[email protected]>
On Jun 24, 2006, at 12:20 PM, Greg Sabino Mullane wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> You need to be looking at strlen(err)-1, as C arrays start counting at
> 0, so "abc\n" has a length of 4, but the newline character is at
> position 3. Try changing your code above to subtract one like this:
>
> if (err[strlen(err)-1] == '\n')
>   err[strlen(err)-1] = 'X';
>

Yes, you are right. If it hadn't been 10 years since I worked in C, I  
may have remembered this. The following is the correct fix (which is  
simply to add the "-1"'s to the strlen() calls). Everything is  
working as expected now.

   if (err[strlen(err)-1] == '\n')
     err[strlen(err)-1] = '\0';

Thanks for all your help, Greg. I'll be able to manually apply this  
my copy of 1.49 and my programmers will be happier. :)

--Joel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.