From: | ilmari(at)ilmari(dot)org (Dagfinn Ilmari Mannsåker ) |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Using the return value of strlcpy() and strlcat() |
Date: | 2019-03-13 15:54:26 |
Message-ID: | d8jk1h26a8d.fsf@dalvik.ping.uio.no |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi hackers,
Over in the "Include all columns in default names for foreign key
constraints" thread[1], I noticed the patch added the following:
+ strlcpy(buf + buflen, name, NAMEDATALEN);
+ buflen += strlen(buf + buflen);
Seeing as strlcpy() returns the copied length, this seems rather
redundant. A quick bit of grepping shows that this pattern occurs in
several places, including the ChooseIndexNameAddition and
ChooseExtendedStatisticNameAddition functions this was no doubt inspired
by.
Attached is a patch that instead uses the return value of strlcpy() and
strlcat(). I left some strlen() calls alone in places where it wasn't
convenient (e.g. pg_open_tzfile(), where it would need an extra
variable).
- ilmari
[1] https://postgr.es/m/CAF+2_SHzBU0tWKvJMZAXfcmrnCwJUeCrAohga0awDf9uDBptnw@mail.gmail.com
--
"A disappointingly low fraction of the human race is,
at any given time, on fire." - Stig Sandbeck Mathisen
Attachment | Content-Type | Size |
---|---|---|
0001-Use-the-return-value-of-strlcpy-and-strlcat.patch | text/x-diff | 5.8 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Julien Rouhaud | 2019-03-13 15:54:42 | Re: Checksum errors in pg_stat_database |
Previous Message | Julien Rouhaud | 2019-03-13 15:53:26 | Re: Checksum errors in pg_stat_database |