Hi !

Sorry for the inconvenience, I wanted to know if this

piece of code seemed to be correct for a OpenBSD developer ?

#define SAFE_FREE(addr)  do { \

  if (addr) \

    { \

      free (addr); \

      addr = NULL; \

    } \

  else \

    { \

      fprintf (stderr, " (double free inside %s:%s) at L%d\n", \

       __FILE__, __func__, __LINE__); \

    } \

  }  while(0);

 

char *

argv_into_line (char **args)

{

  if (args == NULL)

    return NULL;

  size_t offset = 0;

  char **s = args;

  char *line = NULL;

  for (; *s; ++s)

    {

      const size_t len = strlen (*s);

      // pour l'espace et le terminateur

      char *new_line = realloc (line, len + offset + 2);

      if (new_line == NULL) 

      {

          if (line != NULL)

          {

                SAFE_FREE (line);

          }

          break;

      }

      line = new_line;

      memset (&line[offset], 0, len);

     

      strcat (strcat (&line[offset], *s), " ");

      offset += len + 1 ;

    }

  return line;

}

Reply via email to