Skip to content

Commit

Permalink
Requested changes for G_strlcat
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham Vasudeo Desai committed Sep 18, 2024
1 parent de760d8 commit 74b88c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
25 changes: 6 additions & 19 deletions display/d.mon/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ char *get_path(const char *name, int fpath)
char tmpdir[GPATH_MAX];

G_temp_element(tmpdir);
if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) {
G_fatal_error(_("Failed to append '/' to path"));
}
if (G_strlcat(tmpdir, "MONITORS", sizeof(tmpdir)) >= sizeof(tmpdir)) {
G_fatal_error(_("Failed to append 'MONITORS' to path"));
}
(void)G_strlcat(tmpdir, "/", sizeof(tmpdir));
(void)G_strlcat(tmpdir, "MONITORS", sizeof(tmpdir));
if (name) {
if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) {
G_fatal_error(_("Failed to append '/' to path"));
}
(void)G_strlcat(tmpdir, "/", sizeof(tmpdir));
if (G_strlcat(tmpdir, name, sizeof(tmpdir)) >= sizeof(tmpdir)) {
G_fatal_error(_("Failed to append <%s> to path"), name);
}
Expand Down Expand Up @@ -140,16 +134,9 @@ void list_files(const char *name, FILE *fd_out)
DIR *dirp;

G_temp_element(tmpdir);
if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) {
G_fatal_error(_("Failed to append '/' to path"));
}
if (G_strlcat(tmpdir, "MONITORS", sizeof(tmpdir)) >= sizeof(tmpdir)) {
G_fatal_error(_("Failed to append 'MONITORS' to path"));
}

if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) {
G_fatal_error(_("Failed to append '/' to path"));
}
(void)G_strlcat(tmpdir, "/", sizeof(tmpdir));
(void)G_strlcat(tmpdir, "MONITORS", sizeof(tmpdir));
(void)G_strlcat(tmpdir, "/", sizeof(tmpdir));

if (G_strlcat(tmpdir, name, sizeof(tmpdir)) >= sizeof(tmpdir)) {
G_fatal_error(_("Failed to append <%s> to path"), name);
Expand Down
8 changes: 2 additions & 6 deletions display/d.mon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ int main(int argc, char *argv[])
if (list_flag->answer)
G_warning(_("Flag -%c ignored"), list_flag->key);
mon = G_getenv_nofatal("MONITOR");
if (mon && strlen(mon) < GNAME_MAX) {
if (mon) {
if (selected_flag->answer) {
G_verbose_message(_("Currently selected monitor:"));
fprintf(stdout, "%s\n", mon);
Expand All @@ -194,12 +194,8 @@ int main(int argc, char *argv[])
ret = stop_mon(mon);
}
}
else if (!mon) {
else
G_important_message(_("No monitor selected"));
}
else {
G_important_message(_("Monitor name is too long"));
}

exit(EXIT_SUCCESS);
}
Expand Down

0 comments on commit 74b88c4

Please sign in to comment.