[PATCH] replace malloc+strlen+strcpy with strdup

Matt Turner mattst88 at gmail.com
Sun Aug 1 17:27:16 PDT 2010


On Sun, Aug 1, 2010 at 8:13 PM, 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.)
>

Also, pending the comment change in "[PATCH] xfree86: Remove comments
about unable to use malloc."
(http://lists.freedesktop.org/archives/xorg-devel/2010-August/011632.html),
please add the attached malloc+strlen+strcpy->strdup patch as well.

Thanks,
Matt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-replace-more-malloc-strlen-strcpy-with-strdup.patch
Type: application/octet-stream
Size: 956 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20100801/4b1998db/attachment.obj>


More information about the xorg-devel mailing list