libcomps icon indicating copy to clipboard operation
libcomps copied to clipboard

use strdup instead of manual malloc+memcpy

Open ret2libc opened this issue 6 years ago • 2 comments

In multiple places strings are copied from one place to another, but instead of using strdup or the str* functions, the project seems to prefer malloc+memcpy, which IMHO results in less readable more error-prone code.

Examples of this: https://github.com/rpm-software-management/libcomps/blob/2ed0fe52d1e7c062a5a42968bb7a7680835914b8/libcomps/src/comps_objmradix.c#L46 https://github.com/rpm-software-management/libcomps/blob/2ed0fe52d1e7c062a5a42968bb7a7680835914b8/libcomps/src/comps_doc.c#L263 https://github.com/rpm-software-management/libcomps/blob/2ed0fe52d1e7c062a5a42968bb7a7680835914b8/libcomps/src/comps_elem.c#L890 https://github.com/rpm-software-management/libcomps/blob/2ed0fe52d1e7c062a5a42968bb7a7680835914b8/libcomps/src/comps_elem.c#L891 .. and many others.

ret2libc avatar Jan 21 '19 16:01 ret2libc

I agree. The malloc+memcpy style is harder to read. Patch coming soon.

dcantrell avatar May 10 '23 16:05 dcantrell

I agree that it looks not nice but if there is not an issue, I would prefer to keep it like it is. Please look at the patch frequency in the project and you will discover that the project has not much contribution. In future it will be even not used by DNF5.

j-mracek avatar May 15 '23 07:05 j-mracek