| www.delorie.com/archives/browse.cgi | search |
| X-Authentication-Warning: | delorie.com: mail set sender to geda-user-bounces using -f |
| X-Authentication-Warning: | envy.delorie.com: dj set sender to dj AT delorie DOT com using -f |
| From: | DJ Delorie <dj AT delorie DOT com> |
| To: | geda-user AT delorie DOT com |
| Subject: | Re: [geda-user] strncpy in pcb |
| In-Reply-To: | <20230202225152.3539085E50B5@turkos.aspodata.se> |
| (geda-user AT delorie DOT com) | |
| Date: | Thu, 02 Feb 2023 18:32:33 -0500 |
| Message-ID: | <xn4js33apa.fsf@envy.delorie.com> |
| MIME-Version: | 1.0 |
| Reply-To: | geda-user AT delorie DOT com |
| Errors-To: | nobody AT delorie DOT com |
| X-Mailing-List: | geda-user AT delorie DOT com |
| X-Unsubscribes-To: | listserv AT delorie DOT com |
"karl AT aspodata DOT se [via geda-user AT delorie DOT com]" <geda-user AT delorie DOT com>
writes:
> Well, add a dst[sizeof(dst)-1] = '\0' then.
I'd rather fix it the right way than patch over the limitations of using
the wrong function in the first place.
>> strncpy can't be made to do that. Neither can strlcpy for that matter.
>> strcpy_s can but it isn't generally available yet.
>
> should it handle overlapping strings ?
None of those can.
>> What we need is something like:
>>
>> pcb_strcpy (s, d, l)
>> {
>> i = strlen(s);
>> if (i+1 <= l)
>> memcpy (s, d, i+1)
>> else
>> abort()
>> }
>
> I'm not found of abort().
"something like" not "exactly this"
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |