summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2014-10-08 17:35:59 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2014-10-08 17:35:59 +0000
commitdc3a4c54a20ba89e33051d03b15794332510dd6e (patch)
treebe14ed549633da623be705739517d78eb3e8ea3c /usr.bin/tmux
parentffd63c643fb91665eb6cd4e412079a391a52b979 (diff)
Add xreallocarray and remove nmemb argument from xrealloc.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/array.h6
-rw-r--r--usr.bin/tmux/cmd-capture-pane.c4
-rw-r--r--usr.bin/tmux/cmd-save-buffer.c4
-rw-r--r--usr.bin/tmux/cmd-set-buffer.c4
-rw-r--r--usr.bin/tmux/cmd-string.c21
-rw-r--r--usr.bin/tmux/cmd.c8
-rw-r--r--usr.bin/tmux/format.c10
-rw-r--r--usr.bin/tmux/grid.c16
-rw-r--r--usr.bin/tmux/input.c6
-rw-r--r--usr.bin/tmux/paste.c4
-rw-r--r--usr.bin/tmux/screen.c6
-rw-r--r--usr.bin/tmux/status.c8
-rw-r--r--usr.bin/tmux/tmux.h5
-rw-r--r--usr.bin/tmux/utf8.c10
-rw-r--r--usr.bin/tmux/window-choose.c4
-rw-r--r--usr.bin/tmux/window-copy.c12
-rw-r--r--usr.bin/tmux/xmalloc.c19
17 files changed, 82 insertions, 65 deletions
diff --git a/usr.bin/tmux/array.h b/usr.bin/tmux/array.h
index e4a9d690bfd..f2887063afa 100644
--- a/usr.bin/tmux/array.h
+++ b/usr.bin/tmux/array.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: array.h,v 1.6 2012/07/10 11:53:01 nicm Exp $ */
+/* $OpenBSD: array.h,v 1.7 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -39,10 +39,10 @@
fatalx("size too big"); \
if ((a)->space == 0) { \
(a)->space = ARRAY_INITIALSPACE(a); \
- (a)->list = xrealloc((a)->list, 1, (a)->space); \
+ (a)->list = xrealloc((a)->list, (a)->space); \
} \
while ((a)->space <= ((a)->num + (n)) * ARRAY_ITEMSIZE(a)) { \
- (a)->list = xrealloc((a)->list, 2, (a)->space); \
+ (a)->list = xreallocarray((a)->list, 2, (a)->space); \
(a)->space *= 2; \
} \
} while (0)
diff --git a/usr.bin/tmux/cmd-capture-pane.c b/usr.bin/tmux/cmd-capture-pane.c
index b6d57955c06..f9f5682c35b 100644
--- a/usr.bin/tmux/cmd-capture-pane.c
+++ b/usr.bin/tmux/cmd-capture-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-capture-pane.c,v 1.28 2014/06/20 10:46:59 nicm Exp $ */
+/* $OpenBSD: cmd-capture-pane.c,v 1.29 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
@@ -48,7 +48,7 @@ const struct cmd_entry cmd_capture_pane_entry = {
char *
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
{
- buf = xrealloc(buf, 1, *len + linelen + 1);
+ buf = xrealloc(buf, *len + linelen + 1);
memcpy(buf + *len, line, linelen);
*len += linelen;
return (buf);
diff --git a/usr.bin/tmux/cmd-save-buffer.c b/usr.bin/tmux/cmd-save-buffer.c
index 8803aa90c11..de83b5c0f09 100644
--- a/usr.bin/tmux/cmd-save-buffer.c
+++ b/usr.bin/tmux/cmd-save-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-save-buffer.c,v 1.25 2014/05/13 07:34:35 nicm Exp $ */
+/* $OpenBSD: cmd-save-buffer.c,v 1.26 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -147,7 +147,7 @@ do_print:
size = pb->size - used;
msglen = size * 4 + 1;
- msg = xrealloc(msg, 1, msglen);
+ msg = xrealloc(msg, msglen);
strvisx(msg, start, size, VIS_OCTAL|VIS_TAB);
cmdq_print(cmdq, "%s", msg);
diff --git a/usr.bin/tmux/cmd-set-buffer.c b/usr.bin/tmux/cmd-set-buffer.c
index e80727899df..0f5d4e995b6 100644
--- a/usr.bin/tmux/cmd-set-buffer.c
+++ b/usr.bin/tmux/cmd-set-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-buffer.c,v 1.18 2014/05/13 07:34:35 nicm Exp $ */
+/* $OpenBSD: cmd-set-buffer.c,v 1.19 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -104,7 +104,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
memcpy(pdata, pb->data, psize);
}
- pdata = xrealloc(pdata, 1, psize + newsize);
+ pdata = xrealloc(pdata, psize + newsize);
memcpy(pdata + psize, args->argv[0], newsize);
psize += newsize;
diff --git a/usr.bin/tmux/cmd-string.c b/usr.bin/tmux/cmd-string.c
index 9a817a7c8e0..3c665d22f9b 100644
--- a/usr.bin/tmux/cmd-string.c
+++ b/usr.bin/tmux/cmd-string.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-string.c,v 1.19 2013/10/10 12:14:09 nicm Exp $ */
+/* $OpenBSD: cmd-string.c,v 1.20 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -107,10 +107,11 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
case ' ':
case '\t':
if (buf != NULL) {
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len] = '\0';
- argv = xrealloc(argv, argc + 1, sizeof *argv);
+ argv = xreallocarray(argv, argc + 1,
+ sizeof *argv);
argv[argc++] = buf;
buf = NULL;
@@ -151,7 +152,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
if (len >= SIZE_MAX - 2)
goto error;
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len++] = ch;
break;
}
@@ -179,7 +180,7 @@ cmd_string_copy(char **dst, char *src, size_t *len)
srclen = strlen(src);
- *dst = xrealloc(*dst, 1, *len + srclen + 1);
+ *dst = xrealloc(*dst, *len + srclen + 1);
strlcpy(*dst + *len, src, srclen + 1);
*len += srclen;
@@ -231,11 +232,11 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
if (len >= SIZE_MAX - 2)
goto error;
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len++] = ch;
}
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len] = '\0';
return (buf);
@@ -278,7 +279,7 @@ cmd_string_variable(const char *s, size_t *p)
return (t);
}
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len++] = ch;
for (;;) {
@@ -288,7 +289,7 @@ cmd_string_variable(const char *s, size_t *p)
else {
if (len >= SIZE_MAX - 3)
goto error;
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len++] = ch;
}
}
@@ -299,7 +300,7 @@ cmd_string_variable(const char *s, size_t *p)
if (ch != EOF && fch != '{')
cmd_string_ungetc(p); /* ch */
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
buf[len] = '\0';
envent = environ_find(&global_environ, buf);
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index b903f95b9a9..f81f0f19030 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.97 2014/09/25 12:51:40 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.98 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -222,7 +222,7 @@ cmd_stringify_argv(int argc, char **argv)
for (i = 0; i < argc; i++) {
len += strlen(argv[i]) + 1;
- buf = xrealloc(buf, 1, len);
+ buf = xrealloc(buf, len);
if (i == 0)
*buf = '\0';
@@ -1302,11 +1302,11 @@ cmd_template_replace(const char *template, const char *s, int idx)
ptr++;
len += strlen(s);
- buf = xrealloc(buf, 1, len + 1);
+ buf = xrealloc(buf, len + 1);
strlcat(buf, s, len + 1);
continue;
}
- buf = xrealloc(buf, 1, len + 2);
+ buf = xrealloc(buf, len + 2);
buf[len++] = ch;
buf[len] = '\0';
}
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 7a23f7403c6..26ccfed8955 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.49 2014/09/08 14:29:05 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.50 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -267,7 +267,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
/* Expand the buffer and copy in the value. */
while (*len - *off < valuelen + 1) {
- *buf = xrealloc(*buf, 2, *len);
+ *buf = xreallocarray(*buf, 2, *len);
*len *= 2;
}
memcpy(*buf + *off, value, valuelen);
@@ -298,7 +298,7 @@ format_expand(struct format_tree *ft, const char *fmt)
while (*fmt != '\0') {
if (*fmt != '#') {
while (len - off < 2) {
- buf = xrealloc(buf, 2, len);
+ buf = xreallocarray(buf, 2, len);
len *= 2;
}
buf[off++] = *fmt++;
@@ -326,7 +326,7 @@ format_expand(struct format_tree *ft, const char *fmt)
continue;
case '#':
while (len - off < 2) {
- buf = xrealloc(buf, 2, len);
+ buf = xreallocarray(buf, 2, len);
len *= 2;
}
buf[off++] = '#';
@@ -339,7 +339,7 @@ format_expand(struct format_tree *ft, const char *fmt)
s = format_lower[ch - 'a'];
if (s == NULL) {
while (len - off < 3) {
- buf = xrealloc(buf, 2, len);
+ buf = xreallocarray(buf, 2, len);
len *= 2;
}
buf[off++] = '#';
diff --git a/usr.bin/tmux/grid.c b/usr.bin/tmux/grid.c
index 5c53bc7d6c0..9d750a14dba 100644
--- a/usr.bin/tmux/grid.c
+++ b/usr.bin/tmux/grid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grid.c,v 1.40 2014/10/08 17:14:04 nicm Exp $ */
+/* $OpenBSD: grid.c,v 1.41 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -172,7 +172,8 @@ grid_scroll_history(struct grid *gd)
u_int yy;
yy = gd->hsize + gd->sy;
- gd->linedata = xrealloc(gd->linedata, yy + 1, sizeof *gd->linedata);
+ gd->linedata = xreallocarray(gd->linedata, yy + 1,
+ sizeof *gd->linedata);
memset(&gd->linedata[yy], 0, sizeof gd->linedata[yy]);
gd->hsize++;
@@ -187,7 +188,8 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower)
/* Create a space for a new line. */
yy = gd->hsize + gd->sy;
- gd->linedata = xrealloc(gd->linedata, yy + 1, sizeof *gd->linedata);
+ gd->linedata = xreallocarray(gd->linedata, yy + 1,
+ sizeof *gd->linedata);
/* Move the entire screen down to free a space for this line. */
gl_history = &gd->linedata[gd->hsize];
@@ -221,7 +223,7 @@ grid_expand_line(struct grid *gd, u_int py, u_int sx)
if (sx <= gl->cellsize)
return;
- gl->celldata = xrealloc(gl->celldata, sx, sizeof *gl->celldata);
+ gl->celldata = xreallocarray(gl->celldata, sx, sizeof *gl->celldata);
for (xx = gl->cellsize; xx < sx; xx++)
grid_put_cell(gd, xx, py, &grid_default_cell);
gl->cellsize = sx;
@@ -610,7 +612,7 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
}
while (len < off + size + codelen + 1) {
- buf = xrealloc(buf, 2, len);
+ buf = xreallocarray(buf, 2, len);
len *= 2;
}
@@ -685,7 +687,7 @@ grid_reflow_join(struct grid *dst, u_int *py, struct grid_line *src_gl,
nx = ox + to_copy;
/* Resize the destination line. */
- dst_gl->celldata = xrealloc(dst_gl->celldata, nx,
+ dst_gl->celldata = xreallocarray(dst_gl->celldata, nx,
sizeof *dst_gl->celldata);
dst_gl->cellsize = nx;
@@ -724,7 +726,7 @@ grid_reflow_split(struct grid *dst, u_int *py, struct grid_line *src_gl,
to_copy = src_gl->cellsize;
/* Expand destination line. */
- dst_gl->celldata = xrealloc(NULL, to_copy,
+ dst_gl->celldata = xreallocarray(NULL, to_copy,
sizeof *dst_gl->celldata);
dst_gl->cellsize = to_copy;
dst_gl->flags |= GRID_LINE_WRAPPED;
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c
index 5970f98df10..f22ea03e4a6 100644
--- a/usr.bin/tmux/input.c
+++ b/usr.bin/tmux/input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input.c,v 1.70 2014/08/09 07:33:37 nicm Exp $ */
+/* $OpenBSD: input.c,v 1.71 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -909,7 +909,7 @@ input_ground(struct input_ctx *ictx)
if (ictx->input_space > INPUT_BUF_START) {
ictx->input_space = INPUT_BUF_START;
- ictx->input_buf = xrealloc(ictx->input_buf, 1, INPUT_BUF_START);
+ ictx->input_buf = xrealloc(ictx->input_buf, INPUT_BUF_START);
}
}
@@ -974,7 +974,7 @@ input_input(struct input_ctx *ictx)
ictx->flags |= INPUT_DISCARD;
return (0);
}
- ictx->input_buf = xrealloc(ictx->input_buf, 1, available);
+ ictx->input_buf = xrealloc(ictx->input_buf, available);
ictx->input_space = available;
}
ictx->input_buf[ictx->input_len++] = ictx->ch;
diff --git a/usr.bin/tmux/paste.c b/usr.bin/tmux/paste.c
index 88e03159d0a..7f88c147478 100644
--- a/usr.bin/tmux/paste.c
+++ b/usr.bin/tmux/paste.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: paste.c,v 1.24 2014/10/08 17:14:04 nicm Exp $ */
+/* $OpenBSD: paste.c,v 1.25 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -279,7 +279,7 @@ paste_make_sample(struct paste_buffer *pb, int utf8flag)
len = pb->size;
if (len > width)
len = width;
- buf = xrealloc(NULL, len, 4 + 4);
+ buf = xreallocarray(NULL, len, 4 + 4);
if (utf8flag)
used = utf8_strvis(buf, pb->data, len, flags);
diff --git a/usr.bin/tmux/screen.c b/usr.bin/tmux/screen.c
index b3fe3ba440e..def6469529d 100644
--- a/usr.bin/tmux/screen.c
+++ b/usr.bin/tmux/screen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: screen.c,v 1.29 2014/09/01 21:50:18 nicm Exp $ */
+/* $OpenBSD: screen.c,v 1.30 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -215,8 +215,8 @@ screen_resize_y(struct screen *s, u_int sy)
}
/* Resize line arrays. */
- gd->linedata = xrealloc(
- gd->linedata, gd->hsize + sy, sizeof *gd->linedata);
+ gd->linedata = xreallocarray(gd->linedata, gd->hsize + sy,
+ sizeof *gd->linedata);
/* Size increasing. */
if (sy > oldy) {
diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c
index 3b84c7823c4..ab3f07657b8 100644
--- a/usr.bin/tmux/status.c
+++ b/usr.bin/tmux/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.115 2014/10/02 10:39:43 nicm Exp $ */
+/* $OpenBSD: status.c,v 1.116 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -992,7 +992,7 @@ status_prompt_key(struct client *c, int key)
/* Insert the new word. */
size += strlen(s);
off = first - c->prompt_buffer;
- c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + 1);
+ c->prompt_buffer = xrealloc(c->prompt_buffer, size + 1);
first = c->prompt_buffer + off;
memmove(first + strlen(s), first, n);
memcpy(first, s, strlen(s));
@@ -1170,7 +1170,7 @@ status_prompt_key(struct client *c, int key)
break;
}
- c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + n + 1);
+ c->prompt_buffer = xrealloc(c->prompt_buffer, size + n + 1);
if (c->prompt_index == size) {
memcpy(c->prompt_buffer + c->prompt_index, pb->data, n);
c->prompt_index += n;
@@ -1210,7 +1210,7 @@ status_prompt_key(struct client *c, int key)
case MODEKEY_OTHER:
if ((key & 0xff00) != 0 || key < 32 || key == 127)
break;
- c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + 2);
+ c->prompt_buffer = xrealloc(c->prompt_buffer, size + 2);
if (c->prompt_index == size) {
c->prompt_buffer[c->prompt_index++] = key;
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 8a51d641c57..c433e6cc104 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.471 2014/09/01 21:58:41 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.472 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -2408,7 +2408,8 @@ __dead void printflike1 log_fatalx(const char *, ...);
char *xstrdup(const char *);
void *xcalloc(size_t, size_t);
void *xmalloc(size_t);
-void *xrealloc(void *, size_t, size_t);
+void *xrealloc(void *, size_t);
+void *xreallocarray(void *, size_t, size_t);
int printflike2 xasprintf(char **, const char *, ...);
int xvasprintf(char **, const char *, va_list);
int printflike3 xsnprintf(char *, size_t, const char *, ...);
diff --git a/usr.bin/tmux/utf8.c b/usr.bin/tmux/utf8.c
index 1e6332e1816..4251ccaab65 100644
--- a/usr.bin/tmux/utf8.c
+++ b/usr.bin/tmux/utf8.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: utf8.c,v 1.11 2014/04/17 15:37:55 nicm Exp $ */
+/* $OpenBSD: utf8.c,v 1.12 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -419,7 +419,7 @@ utf8_fromcstr(const char *src)
n = 0;
while (*src != '\0') {
- dst = xrealloc(dst, n + 1, sizeof *dst);
+ dst = xreallocarray(dst, n + 1, sizeof *dst);
if (utf8_open(&dst[n], *src)) {
more = 1;
while (*++src != '\0' && more)
@@ -436,7 +436,7 @@ utf8_fromcstr(const char *src)
n++;
}
- dst = xrealloc(dst, n + 1, sizeof *dst);
+ dst = xreallocarray(dst, n + 1, sizeof *dst);
dst[n].size = 0;
return (dst);
}
@@ -452,12 +452,12 @@ utf8_tocstr(struct utf8_data *src)
n = 0;
for(; src->size != 0; src++) {
- dst = xrealloc(dst, n + src->size, 1);
+ dst = xreallocarray(dst, n + src->size, 1);
memcpy(dst + n, src->data, src->size);
n += src->size;
}
- dst = xrealloc(dst, n + 1, 1);
+ dst = xreallocarray(dst, n + 1, 1);
dst[n] = '\0';
return (dst);
}
diff --git a/usr.bin/tmux/window-choose.c b/usr.bin/tmux/window-choose.c
index 553d3415f33..6aaa0e73133 100644
--- a/usr.bin/tmux/window-choose.c
+++ b/usr.bin/tmux/window-choose.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-choose.c,v 1.54 2014/05/08 07:54:47 nicm Exp $ */
+/* $OpenBSD: window-choose.c,v 1.55 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -317,7 +317,7 @@ window_choose_prompt_input(enum window_choose_input_type input_type,
data->input_prompt = prompt;
input_len = strlen(data->input_str) + 2;
- data->input_str = xrealloc(data->input_str, 1, input_len);
+ data->input_str = xrealloc(data->input_str, input_len);
data->input_str[input_len - 2] = key;
data->input_str[input_len - 1] = '\0';
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index bc650e9a399..b0b9e5acd59 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.115 2014/10/02 08:36:26 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.116 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -794,7 +794,7 @@ window_copy_key_input(struct window_pane *wp, int key)
}
inputlen = strlen(data->inputstr);
- data->inputstr = xrealloc(data->inputstr, 1, inputlen + n + 1);
+ data->inputstr = xrealloc(data->inputstr, inputlen + n + 1);
memcpy(data->inputstr + inputlen, pb->data, n);
data->inputstr[inputlen + n] = '\0';
break;
@@ -840,7 +840,7 @@ window_copy_key_input(struct window_pane *wp, int key)
break;
inputlen = strlen(data->inputstr) + 2;
- data->inputstr = xrealloc(data->inputstr, 1, inputlen);
+ data->inputstr = xrealloc(data->inputstr, inputlen);
data->inputstr[inputlen - 2] = key;
data->inputstr[inputlen - 1] = '\0';
break;
@@ -1533,7 +1533,7 @@ window_copy_append_selection(struct window_pane *wp, const char *bufname)
} else
pb = paste_get_name(bufname);
if (pb != NULL) {
- buf = xrealloc(buf, 1, len + pb->size);
+ buf = xrealloc(buf, len + pb->size);
memmove(buf + pb->size, buf, len);
memcpy(buf, pb->data, pb->size);
len += pb->size;
@@ -1589,7 +1589,7 @@ window_copy_copy_line(struct window_pane *wp,
}
}
- *buf = xrealloc(*buf, 1, (*off) + ud.size);
+ *buf = xrealloc(*buf, (*off) + ud.size);
memcpy(*buf + *off, ud.data, ud.size);
*off += ud.size;
}
@@ -1597,7 +1597,7 @@ window_copy_copy_line(struct window_pane *wp,
/* Only add a newline if the line wasn't wrapped. */
if (!wrapped || ex != xx) {
- *buf = xrealloc(*buf, 1, (*off) + 1);
+ *buf = xrealloc(*buf, (*off) + 1);
(*buf)[(*off)++] = '\n';
}
}
diff --git a/usr.bin/tmux/xmalloc.c b/usr.bin/tmux/xmalloc.c
index 6ef8afd47cd..c0e4167fbb9 100644
--- a/usr.bin/tmux/xmalloc.c
+++ b/usr.bin/tmux/xmalloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xmalloc.c,v 1.4 2012/07/10 11:53:01 nicm Exp $ */
+/* $OpenBSD: xmalloc.c,v 1.5 2014/10/08 17:35:58 nicm Exp $ */
/*
* Copyright (c) 2004 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -68,7 +68,20 @@ xmalloc(size_t size)
}
void *
-xrealloc(void *oldptr, size_t nmemb, size_t size)
+xrealloc(void *oldptr, size_t newsize)
+{
+ void *newptr;
+
+ if (newsize == 0)
+ fatalx("zero size");
+ if ((newptr = realloc(oldptr, newsize)) == NULL)
+ fatal("xrealloc failed");
+
+ return (newptr);
+}
+
+void *
+xreallocarray(void *oldptr, size_t nmemb, size_t size)
{
size_t newsize = nmemb * size;
void *newptr;
@@ -78,7 +91,7 @@ xrealloc(void *oldptr, size_t nmemb, size_t size)
if (SIZE_MAX / nmemb < size)
fatalx("nmemb * size > SIZE_MAX");
if ((newptr = realloc(oldptr, newsize)) == NULL)
- fatal("xrealloc failed");
+ fatal("xreallocarray failed");
return (newptr);
}