mlvwm icon indicating copy to clipboard operation
mlvwm copied to clipboard

Replace `strcpy`/`strcat` use with `strlcpy`/`strlcat`

Open morgant opened this issue 1 year ago • 0 comments

As noted in Issue #48 (see this comment), when building mlvwm with clang under OpenBSD amd64/7.5-stable, I get the following warnings:

mlvwm.c:386(mlvwm.o:(Done)): warning: strcpy() is almost always misused, please use strlcpy()
functions.c:322(functions.o:(ChangeDesk)): warning: sprintf() is often misused, please use snprintf()

There are quite a number of uses of strpy() in mlvwm.c's Done() implementation.

As noted in a comment on Issue #6, I had intended to replace strcat() with strlcat() as part of that move from sprintf() to snprintf(), but held off as strlcat() is generally BSD-specific and not included in Linux's libc. This is true of strlcpy() too.

This is pretty well covered in WikiBook's C Programming/C Reference/nonstandard/strlcpy. Briefly, strlcpy() & strlcat() are implemented for Linux in libbsd, but there may be some minor variations in implementation across other UNIX-like OSes.

I do intend to migrate to strlcpy() & strlcat() using libbsd, but I want to resolve existing issues building/running on Linux distros first, specifically: Arch Linux (Issue #40, Issue #37), Debian (Issue #38), Slackware (Issue #29), and Ubuntu (Issue #1).

morgant avatar Sep 03 '24 20:09 morgant