public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* malloc’ing strcat
@ 2020-02-24  2:58 Alexandre François Garreau
  2020-02-24 11:17 ` Florian Weimer
  0 siblings, 1 reply; 11+ messages in thread
From: Alexandre François Garreau @ 2020-02-24  2:58 UTC (permalink / raw)
  To: libc-help

Hi,

strcat needs a buffer already wide enough to contain concatenation of both 
strings, hence I deduce idiomatic use is to first malloc(strlen(str1) + 
strlen(str2) + 1)…

But then the usage must always be something like:
#define strcat(a, b) strcat (strcpy (malloc (strlen(a) + strlen (b) + 1) 
a), b)
(which, of course, requires further free())…

So is there already a function or macro which does that? if not so, why? 
asprintf&cie already exist, after all…

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-02-25 13:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24  2:58 malloc’ing strcat Alexandre François Garreau
2020-02-24 11:17 ` Florian Weimer
2020-02-24 12:31   ` Alexandre François Garreau
2020-02-24 12:38     ` Florian Weimer
2020-02-24 20:23       ` Alexandre François Garreau
2020-02-24 21:17         ` Florian Weimer
2020-02-25  3:58           ` Alexandre François Garreau
2020-02-25  9:41             ` Florian Weimer
2020-02-25 12:48               ` Alexandre François Garreau
2020-02-25 12:53                 ` Florian Weimer
2020-02-25 13:04                   ` Alexandre François Garreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).