[PATCH] replace malloc+strlen+strcpy with strdup

Keith Packard keithp at keithp.com
Sun Aug 1 19:46:16 PDT 2010


On Sun, 1 Aug 2010 20:13:03 -0400, Matt Turner <mattst88 at gmail.com> wrote:
> On Sat, Jun 19, 2010 at 1:59 PM,  <mattst88 at gmail.com> wrote:
> > From: Matt Turner <mattst88 at gmail.com>
> >
> > Signed-off-by: Matt Turner <mattst88 at gmail.com>
> > ---
> >  dix/extension.c              |    3 +--
> >  hw/xfree86/common/xf86Init.c |    6 ++----
> >  hw/xfree86/parser/scan.c     |    6 ++----
> >  3 files changed, 5 insertions(+), 10 deletions(-)
> >
> > diff --git a/dix/extension.c b/dix/extension.c
> > index c8e921a..1e340ce 100644
> > --- a/dix/extension.c
> > +++ b/dix/extension.c
> > @@ -164,10 +164,9 @@ Bool AddExtensionAlias(char *alias, ExtensionEntry *ext)
> >     if (!aliases)
> >        return FALSE;
> >     ext->aliases = aliases;
> > -    name = malloc(strlen(alias) + 1);
> > +    name = strdup(alias);
> >     if (!name)
> >        return FALSE;
> > -    strcpy(name,  alias);
> >     ext->aliases[ext->num_aliases] = name;
> >     ext->num_aliases++;
> >     return TRUE;
> > diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
> > index ca532ee..4195a09 100644
> > --- a/hw/xfree86/common/xf86Init.c
> > +++ b/hw/xfree86/common/xf86Init.c
> > @@ -1067,10 +1067,9 @@ ddxProcessArgument(int argc, char **argv, int i)
> >     {
> >       char *mp;
> >       CHECK_FOR_REQUIRED_ARGUMENT();
> > -      mp = malloc(strlen(argv[i + 1]) + 1);
> > +      mp = strdup(argv[i + 1]);
> >       if (!mp)
> >        FatalError("Can't allocate memory for ModulePath\n");
> > -      strcpy(mp, argv[i + 1]);
> >       xf86ModulePath = mp;
> >       xf86ModPathFrom = X_CMDLINE;
> >       return 2;
> > @@ -1079,10 +1078,9 @@ ddxProcessArgument(int argc, char **argv, int i)
> >     {
> >       char *lf;
> >       CHECK_FOR_REQUIRED_ARGUMENT();
> > -      lf = malloc(strlen(argv[i + 1]) + 1);
> > +      lf = strdup(argv[i + 1]);
> >       if (!lf)
> >        FatalError("Can't allocate memory for LogFile\n");
> > -      strcpy(lf, argv[i + 1]);
> >       xf86LogFile = lf;
> >       xf86LogFileFrom = X_CMDLINE;
> >       return 2;
> > diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
> > index 5312143..ada3910 100644
> > --- a/hw/xfree86/parser/scan.c
> > +++ b/hw/xfree86/parser/scan.c
> > @@ -451,8 +451,7 @@ again:
> >                        }
> >                        while ((c != '\"') && (c != '\n') && (c != '\r') && (c != '\0'));
> >                        configRBuf[i] = '\0';
> > -                       val.str = malloc (strlen (configRBuf) + 1);
> > -                       strcpy (val.str, configRBuf);   /* private copy ! */
> > +                       val.str = strdup(configRBuf);   /* private copy ! */
> >                        return STRING;
> >                }
> >
> > @@ -1088,8 +1087,7 @@ void
> >  xf86setSection (char *section)
> >  {
> >        free(configSection);
> > -       configSection = malloc(strlen (section) + 1);
> > -       strcpy (configSection, section);
> > +       configSection = strdup(section);
> >  }
> >
> >  /*
> > --
> > 1.6.4.4
> 
> Ready to be applied, Keith. (I totally forgot to ping you about this.)

No worries; changes like this are welcome, but not for 1.9 as we're
getting close to the release and only merging patches that fix known
issues. I'm not currently tracking fixes to be applied after 1.9.

-- 
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20100801/ccda5f6c/attachment.pgp>


More information about the xorg-devel mailing list