[PATCH:libXfont 2/2] Replace malloc(strlen)+strcpy/strcat calls with strdup

Jasper St. Pierre jstpierre at mecheye.net
Wed Oct 30 03:07:20 CET 2013


On Tue, Oct 29, 2013 at 9:55 PM, Alan Coopersmith <
alan.coopersmith at oracle.com> wrote:

> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
>  src/FreeType/ftfuncs.c |    4 +---
>  src/FreeType/xttcap.c  |    3 +--
>  src/fontfile/fontdir.c |   10 +++-------
>  3 files changed, 5 insertions(+), 12 deletions(-)
>
> diff --git a/src/FreeType/ftfuncs.c b/src/FreeType/ftfuncs.c
> index 091339d..2c90cf9 100644
> --- a/src/FreeType/ftfuncs.c
> +++ b/src/FreeType/ftfuncs.c
> @@ -2289,13 +2289,11 @@ FreeTypeSetUpTTCap( char *fileName,
> FontScalablePtr vals,
>             }
>         }
>         else{
> -           *dynStrFTFileName = malloc(strlen(*dynStrRealFileName)+1);
> +           *dynStrFTFileName = strdup(*dynStrRealFileName);
>             if( *dynStrFTFileName == NULL ){
>                 result = AllocError;
>                 goto quit;
>             }
> -           **dynStrFTFileName = '\0';
> -           strcat(*dynStrFTFileName,*dynStrRealFileName);
>         }
>      }
>      /*
> diff --git a/src/FreeType/xttcap.c b/src/FreeType/xttcap.c
> index c1d8e67..104dc89 100644
> --- a/src/FreeType/xttcap.c
> +++ b/src/FreeType/xttcap.c
> @@ -234,14 +234,13 @@ SPropRecValList_add_record(SDynPropRecValList
> *pThisList,
>              {
>                  char *p;
>
> -                if (NULL == (p = malloc(strlen(strValue)+1))) {
> +                if (NULL == (p = strdup(strValue))) {
>                      fprintf(stderr,
>                              "truetype font property : "
>                              "cannot allocate memory.\n");
>                      result = True;
>                      goto quit;
>                  }
> -                strcpy(p, strValue);
>                  SPropContainer_value_str(&tmpContainerE) = p;
>              }
>              break;
> diff --git a/src/fontfile/fontdir.c b/src/fontfile/fontdir.c
> index 97b2ba3..ef7ffa5 100644
> --- a/src/fontfile/fontdir.c
> +++ b/src/fontfile/fontdir.c
> @@ -425,17 +425,13 @@ FontFileCountDashes (char *name, int namelen)
>      return ndashes;
>  }
>
> +/* exported in public API in <X11/fonts/fntfil.h> */
>  char *
>  FontFileSaveString (char *s)
>  {
> -    char    *n;
> -
> -    n = malloc (strlen (s) + 1);
> -    if (!n)
> -       return 0;
> -    strcpy (n, s);
> -    return n;
> +    return strdup(s);
>  }
> +#define FontFileSaveString(s) strdup(s)
>

Shouldn't this #define be in a header file to be useful?


>  FontEntryPtr
>  FontFileFindNameInScalableDir(FontTablePtr table, FontNamePtr pat,
> --
> 1.7.9.2
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>



-- 
  Jasper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg-devel/attachments/20131029/27b6dea3/attachment.html>


More information about the xorg-devel mailing list