summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOkan Demirmen <okan@cvs.openbsd.org>2018-02-02 13:27:26 +0000
committerOkan Demirmen <okan@cvs.openbsd.org>2018-02-02 13:27:26 +0000
commit6c840e08917bb23cf9ac3bdb803a31b74f2610a3 (patch)
tree0e8d4666ef8574de8b612c67a3480210fe0b783a
parent736d143a867d21d9dce479bdc09f92a7ec615984 (diff)
Simplification; use asprintf where appropriate now.
-rw-r--r--app/cwm/calmwm.h10
-rw-r--r--app/cwm/conf.c62
-rw-r--r--app/cwm/parse.y12
-rw-r--r--app/cwm/search.c8
4 files changed, 43 insertions, 49 deletions
diff --git a/app/cwm/calmwm.h b/app/cwm/calmwm.h
index 894f842ad..c9fd91d8e 100644
--- a/app/cwm/calmwm.h
+++ b/app/cwm/calmwm.h
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: calmwm.h,v 1.353 2018/02/01 15:17:51 okan Exp $
+ * $OpenBSD: calmwm.h,v 1.354 2018/02/02 13:27:25 okan Exp $
*/
#ifndef _CALMWM_H_
@@ -260,7 +260,7 @@ TAILQ_HEAD(mousebind_q, bind_ctx);
struct cmd_ctx {
TAILQ_ENTRY(cmd_ctx) entry;
char *name;
- char path[PATH_MAX];
+ char *path;
};
TAILQ_HEAD(cmd_q, cmd_ctx);
TAILQ_HEAD(wm_q, cmd_ctx);
@@ -298,13 +298,13 @@ struct conf {
int snapdist;
struct gap gap;
char *color[CWM_COLOR_NITEMS];
- char known_hosts[PATH_MAX];
char *font;
char *wmname;
Cursor cursor[CF_NITEMS];
int xrandr;
int xrandr_event_base;
char *homedir;
+ char *known_hosts;
char *wm_argv;
};
@@ -540,9 +540,9 @@ int conf_bind_mouse(struct conf *, const char *,
const char *);
void conf_clear(struct conf *);
void conf_client(struct client_ctx *);
-int conf_cmd_add(struct conf *, const char *,
+void conf_cmd_add(struct conf *, const char *,
const char *);
-int conf_wm_add(struct conf *, const char *,
+void conf_wm_add(struct conf *, const char *,
const char *);
void conf_cursor(struct conf *);
void conf_grab_kbd(Window);
diff --git a/app/cwm/conf.c b/app/cwm/conf.c
index 790daa2a0..af76f6d5a 100644
--- a/app/cwm/conf.c
+++ b/app/cwm/conf.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: conf.c,v 1.238 2018/01/23 16:00:21 okan Exp $
+ * $OpenBSD: conf.c,v 1.239 2018/02/02 13:27:25 okan Exp $
*/
#include <sys/types.h>
@@ -33,7 +33,6 @@
#include "calmwm.h"
static const char *conf_bind_getmask(const char *, unsigned int *);
-static void conf_cmd_remove(struct conf *, const char *);
static void conf_unbind_key(struct conf *, struct bind_ctx *);
static void conf_unbind_mouse(struct conf *, struct bind_ctx *);
@@ -279,8 +278,7 @@ conf_init(struct conf *c)
conf_wm_add(c, "cwm", "cwm");
- (void)snprintf(c->known_hosts, sizeof(c->known_hosts), "%s/%s",
- c->homedir, ".ssh/known_hosts");
+ xasprintf(&c->known_hosts, "%s/%s", c->homedir, ".ssh/known_hosts");
c->font = xstrdup("sans-serif:pixelsize=14:bold");
c->wmname = xstrdup("CWM");
@@ -298,11 +296,13 @@ conf_clear(struct conf *c)
while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) {
TAILQ_REMOVE(&c->cmdq, cmd, entry);
free(cmd->name);
+ free(cmd->path);
free(cmd);
}
while ((wm = TAILQ_FIRST(&c->wmq)) != NULL) {
TAILQ_REMOVE(&c->wmq, wm, entry);
free(wm->name);
+ free(wm->path);
free(wm);
}
while ((kb = TAILQ_FIRST(&c->keybindq)) != NULL) {
@@ -327,57 +327,49 @@ conf_clear(struct conf *c)
for (i = 0; i < CWM_COLOR_NITEMS; i++)
free(c->color[i]);
+ free(c->known_hosts);
free(c->font);
free(c->wmname);
}
-int
+void
conf_cmd_add(struct conf *c, const char *name, const char *path)
{
- struct cmd_ctx *cmd;
+ struct cmd_ctx *cmd, *cmdtmp = NULL, *cmdnxt;
cmd = xmalloc(sizeof(*cmd));
cmd->name = xstrdup(name);
- if (strlcpy(cmd->path, path, sizeof(cmd->path)) >= sizeof(cmd->path)) {
- free(cmd->name);
- free(cmd);
- return(0);
- }
- conf_cmd_remove(c, name);
-
- TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
- return(1);
-}
-
-static void
-conf_cmd_remove(struct conf *c, const char *name)
-{
- struct cmd_ctx *cmd = NULL, *cmdnxt;
-
- TAILQ_FOREACH_SAFE(cmd, &c->cmdq, entry, cmdnxt) {
- if (strcmp(cmd->name, name) == 0) {
- TAILQ_REMOVE(&c->cmdq, cmd, entry);
- free(cmd->name);
- free(cmd);
+ cmd->path = xstrdup(path);
+
+ TAILQ_FOREACH_SAFE(cmdtmp, &c->cmdq, entry, cmdnxt) {
+ if (strcmp(cmdtmp->name, name) == 0) {
+ TAILQ_REMOVE(&c->cmdq, cmdtmp, entry);
+ free(cmdtmp->name);
+ free(cmdtmp->path);
+ free(cmdtmp);
}
}
+ TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
}
-int
+void
conf_wm_add(struct conf *c, const char *name, const char *path)
{
- struct cmd_ctx *wm;
+ struct cmd_ctx *wm, *wmtmp = NULL, *wmnxt;
wm = xmalloc(sizeof(*wm));
wm->name = xstrdup(name);
- if (strlcpy(wm->path, path, sizeof(wm->path)) >= sizeof(wm->path)) {
- free(wm->name);
- free(wm);
- return(0);
+ wm->path = xstrdup(path);
+
+ TAILQ_FOREACH_SAFE(wmtmp, &c->cmdq, entry, wmnxt) {
+ if (strcmp(wmtmp->name, name) == 0) {
+ TAILQ_REMOVE(&c->wmq, wmtmp, entry);
+ free(wmtmp->name);
+ free(wmtmp->path);
+ free(wmtmp);
+ }
}
-
TAILQ_INSERT_TAIL(&c->wmq, wm, entry);
- return(1);
}
void
diff --git a/app/cwm/parse.y b/app/cwm/parse.y
index b8a72cb06..0c1972cc4 100644
--- a/app/cwm/parse.y
+++ b/app/cwm/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.69 2017/12/29 20:03:46 okan Exp $ */
+/* $OpenBSD: parse.y,v 1.70 2018/02/02 13:27:25 okan Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -137,22 +137,24 @@ main : FONTNAME STRING {
conf->snapdist = $2;
}
| COMMAND STRING string {
- if (!conf_cmd_add(conf, $2, $3)) {
- yyerror("command name/path too long");
+ if (strlen($3) >= PATH_MAX) {
+ yyerror("%s command path too long", $2);
free($2);
free($3);
YYERROR;
}
+ conf_cmd_add(conf, $2, $3);
free($2);
free($3);
}
| WM STRING string {
- if (!conf_wm_add(conf, $2, $3)) {
- yyerror("wm name/path too long");
+ if (strlen($3) >= PATH_MAX) {
+ yyerror("%s wm path too long", $2);
free($2);
free($3);
YYERROR;
}
+ conf_wm_add(conf, $2, $3);
free($2);
free($3);
}
diff --git a/app/cwm/search.c b/app/cwm/search.c
index fde91af94..ff17492d8 100644
--- a/app/cwm/search.c
+++ b/app/cwm/search.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: search.c,v 1.68 2018/01/23 13:51:39 okan Exp $
+ * $OpenBSD: search.c,v 1.69 2018/02/02 13:27:25 okan Exp $
*/
#include <sys/types.h>
@@ -162,12 +162,11 @@ static void
match_path_type(struct menu_q *resultq, char *search, int flag)
{
struct menu *mi;
- char pattern[PATH_MAX];
+ char *pattern;
glob_t g;
int i;
- (void)strlcpy(pattern, search, sizeof(pattern));
- (void)strlcat(pattern, "*", sizeof(pattern));
+ xasprintf(&pattern, "%s*", search);
if (glob(pattern, GLOB_MARK, NULL, &g) != 0)
return;
for (i = 0; i < g.gl_pathc; i++) {
@@ -178,6 +177,7 @@ match_path_type(struct menu_q *resultq, char *search, int flag)
TAILQ_INSERT_TAIL(resultq, mi, resultentry);
}
globfree(&g);
+ free(pattern);
}
void