[physfs] Replace malloc/strcpy by strdup

Tim Cas darkuranium at gmail.com
Wed Sep 29 12:07:50 EDT 2010

>Perhaps, it might be an idea to get rid of dynamically allocated
>path strings, and use arrays instead ? This might vastly improve
>performance at cost of memory, I suspect.
You mean using "char foo[5]" as opposed to "char* foo = malloc(5)"? I'm not
sure what you mean because dynamically allocated path strings are pretty
much arrays (all strings are).

If you do mean using foo[5], then there's no change, only that it allocates
things on the stack, which is much more limited and can have horrible
consequences if an overflow happens. Furthermore, the size is fixed, meaning
that you can't, in this extreme case, use the path "hello" because it uses 6
characters ("hello" + \0 termination).

On 29 September 2010 17:58, Tolga Dalman <tolga.dalman at googlemail.com>wrote:

> Hash: SHA1
> On 09/29/10 17:33, Christoph Nelles wrote:
> > yes, looks like this is a problem:
> > http://stackoverflow.com/questions/482375/strdup-function
> Indeed, strdup is POSIX only.
> > And you are forced to use free(). allocator.malloc/free may use other
> > functions.
> >
> > So why worrying about saving one LOC.
> Actually, I sent the patch for fixing the erroneous check.
> Perhaps, it might be an idea to get rid of dynamically allocated
> path strings, and use arrays instead ? This might vastly improve
> performance at cost of memory, I suspect.
> Are there any PhysFS performance tests available ?
> Version: GnuPG v2.0.16 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> iQEcBAEBAgAGBQJMo2ImAAoJEI0vwg8AaIlUfIoH/1Y9rW3dTwx87Pemd2CAIBA+
> 2blCY09qmG4kS6R5wM21/V14AK0FW8IAsxJsUExr5KxL1ZnH3xWTFcwkKkuiv++c
> bXQEvICh6s2ldCuZ988GZChVMtHuNpY3z5UcsgGVEZcr3QXL6wI9hbcPRhCITMkT
> dUmGGIYj3QcV2i2Ou+kBCPyLpAZnPyVDujBWJbw2Jk0BxzMxKFS+/9QM8qre74kH
> gSdZRx2QE58yVQU+IPiUdpUAiM21GBvyqgUyoOnrD2leCa0jozz8l9P27cVbUWun
> pqdKTf8XnRmIfntW3NqYXieTZI+MPeilKNZtJBUQ9JbrjpFPSVFs8ouOGHeWOPk=
> =151X
> _______________________________________________
> physfs mailing list
> physfs at icculus.org
> http://icculus.org/mailman/listinfo/physfs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://icculus.org/pipermail/physfs/attachments/20100929/979897e4/attachment.htm>

More information about the physfs mailing list