Merge pull request #865 from martinetd/str_truncation
Fix gcc string truncation warnings
This commit is contained in:
commit
4dbf7f8b88
|
@ -202,7 +202,10 @@ struct example_config *parse_args(int argc, char *argv[]) {
|
||||||
char cwd[MAXPATHLEN];
|
char cwd[MAXPATHLEN];
|
||||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||||
char buf[MAXPATHLEN];
|
char buf[MAXPATHLEN];
|
||||||
snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "wlr-example.ini");
|
if (snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "wlr-example.ini") >= MAXPATHLEN) {
|
||||||
|
wlr_log(L_ERROR, "config path too long");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
config->config_path = strdup(buf);
|
config->config_path = strdup(buf);
|
||||||
} else {
|
} else {
|
||||||
wlr_log(L_ERROR, "could not get cwd");
|
wlr_log(L_ERROR, "could not get cwd");
|
||||||
|
|
|
@ -64,7 +64,7 @@ static char* find_chars_or_comment(const char* s, const char* chars)
|
||||||
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
|
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
|
||||||
static char* strncpy0(char* dest, const char* src, size_t size)
|
static char* strncpy0(char* dest, const char* src, size_t size)
|
||||||
{
|
{
|
||||||
strncpy(dest, src, size);
|
strncpy(dest, src, size-1);
|
||||||
dest[size - 1] = '\0';
|
dest[size - 1] = '\0';
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ struct wlr_output {
|
||||||
struct wl_global *wl_global;
|
struct wl_global *wl_global;
|
||||||
struct wl_list wl_resources;
|
struct wl_list wl_resources;
|
||||||
|
|
||||||
char name[16];
|
char name[24];
|
||||||
char make[48];
|
char make[48];
|
||||||
char model[16];
|
char model[16];
|
||||||
char serial[16];
|
char serial[16];
|
||||||
|
|
|
@ -418,7 +418,10 @@ struct roots_config *roots_config_create_from_args(int argc, char *argv[]) {
|
||||||
char cwd[MAXPATHLEN];
|
char cwd[MAXPATHLEN];
|
||||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||||
char buf[MAXPATHLEN];
|
char buf[MAXPATHLEN];
|
||||||
snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "rootston.ini");
|
if (snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "rootston.ini") >= MAXPATHLEN) {
|
||||||
|
wlr_log(L_ERROR, "config path too long");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
config->config_path = strdup(buf);
|
config->config_path = strdup(buf);
|
||||||
} else {
|
} else {
|
||||||
wlr_log(L_ERROR, "could not get cwd");
|
wlr_log(L_ERROR, "could not get cwd");
|
||||||
|
|
|
@ -64,7 +64,7 @@ static char* find_chars_or_comment(const char* s, const char* chars)
|
||||||
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
|
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
|
||||||
static char* strncpy0(char* dest, const char* src, size_t size)
|
static char* strncpy0(char* dest, const char* src, size_t size)
|
||||||
{
|
{
|
||||||
strncpy(dest, src, size);
|
strncpy(dest, src, size-1);
|
||||||
dest[size - 1] = '\0';
|
dest[size - 1] = '\0';
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue