Comment inline. On Wed, Dec 13, 2023 at 12:55:27PM +0100, Roberto E. Vargas Caballero wrote: > This makes possible to use the function to initialize the string from > an existing char array. > --- > ed.c | 30 +++++++++++++++++++++--------- > 1 file changed, 21 insertions(+), 9 deletions(-) > > diff --git a/ed.c b/ed.c > index b430e74..13e956a 100644 > --- a/ed.c > +++ b/ed.c > @@ -122,12 +122,24 @@ prevln(int line) > } > > static String * > -string(String *s) > +string(String *s, char *from)
Nit as it's more a matter of style: I'd prefer to have one function to create a String and another function to create a String from a char array. This would make a cleaner interface and avoids passing and dealing with NULL all the time. > { > + size_t len; > + char *t; > + > + if (!from) { > + len = 0; > + t = NULL; > + } else { > + if ((t = strdup(from)) == NULL) > + error("out of memory"); > + len = strlen(t); > + }