hotlist.c, code beautification
Roland Illig
roland.illig at gmx.de
Wed Nov 10 17:21:58 UTC 2004
Hi,
I have rewritten parts of hotlist.c to be easier to understand. (I hope
it really will.) I think the patched version makes it clear which
function is responsible for freeing the allocated memory. These are the
changes I made.
add2hotlist gets "const char *" arguments instead of "char *". It will
then create local copies with g_strdup() as needed. This way it will not
be possible after the return of add2hotlist() to alter the strings that
are saved. You can also be sure that add2hotlist does not free the
strings you are passing.
In the function add_new_entry_input the "inout" r1 and r2 arguments are
splitted into "in" arguments and "out" arguments. The "in" arguments are
not modified by the function and have nothing to do with the "out"
arguments, so why should they be passed using the same variable?
The main changes are in the function add_new_entry_cmd. All variables
that probably contain allocated strings are explicitly initialized. This
is especially important for title and url, as the function
add_new_entry_input does not give any guarantees about the return value
in case of an error. Each of these variables will never be assigned more
than one value. After all the work has been done, they are freed.
Roland
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hotlist.patch
Type: text/x-patch
Size: 2972 bytes
Desc: not available
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20041110/da4ce73c/attachment.bin>
More information about the mc-devel
mailing list