Merge branch 'master' of github.com:tmux/tmux

This commit is contained in:
Nicholas Marriott 2015-11-18 12:55:22 +00:00
commit 93742ed5df
2 changed files with 26 additions and 31 deletions

View File

@ -130,10 +130,6 @@ session_create(const char *name, int argc, char **argv, const char *path,
memcpy(s->tio, tio, sizeof *s->tio); memcpy(s->tio, tio, sizeof *s->tio);
} }
if (gettimeofday(&s->creation_time, NULL) != 0)
fatal("gettimeofday failed");
session_update_activity(s, &s->creation_time);
s->sx = sx; s->sx = sx;
s->sy = sy; s->sy = sy;
@ -150,6 +146,8 @@ session_create(const char *name, int argc, char **argv, const char *path,
} }
RB_INSERT(sessions, &sessions, s); RB_INSERT(sessions, &sessions, s);
log_debug("new session %s $%u", s->name, s->id);
if (gettimeofday(&s->creation_time, NULL) != 0) if (gettimeofday(&s->creation_time, NULL) != 0)
fatal("gettimeofday failed"); fatal("gettimeofday failed");
session_update_activity(s, &s->creation_time); session_update_activity(s, &s->creation_time);
@ -264,6 +262,10 @@ session_update_activity(struct session *s, struct timeval *from)
else else
memcpy(&s->activity_time, from, sizeof s->activity_time); memcpy(&s->activity_time, from, sizeof s->activity_time);
log_debug("session %s activity %lld.%06d (last %lld.%06d)", s->name,
(long long)s->activity_time.tv_sec, (int)s->activity_time.tv_usec,
(long long)last->tv_sec, (int)last->tv_usec);
if (evtimer_initialized(&s->lock_timer)) if (evtimer_initialized(&s->lock_timer))
evtimer_del(&s->lock_timer); evtimer_del(&s->lock_timer);
else else

View File

@ -25,16 +25,13 @@
#include "tmux.h" #include "tmux.h"
char * char *
xstrdup(const char *s) xstrdup(const char *str)
{ {
char *ptr; char *cp;
size_t len;
len = strlen(s) + 1; if ((cp = strdup(str)) == NULL)
ptr = xmalloc(len); fatal("xstrdup");
return (cp);
strlcpy(ptr, s, len);
return (ptr);
} }
void * void *
@ -43,11 +40,9 @@ xcalloc(size_t nmemb, size_t size)
void *ptr; void *ptr;
if (size == 0 || nmemb == 0) if (size == 0 || nmemb == 0)
fatalx("zero size"); fatalx("xcalloc: zero size");
if (SIZE_MAX / nmemb < size)
fatalx("nmemb * size > SIZE_MAX");
if ((ptr = calloc(nmemb, size)) == NULL) if ((ptr = calloc(nmemb, size)) == NULL)
fatal("xcalloc failed"); log_fatal("xcalloc: allocating %zu bytes", size);
return (ptr); return (ptr);
} }
@ -58,9 +53,9 @@ xmalloc(size_t size)
void *ptr; void *ptr;
if (size == 0) if (size == 0)
fatalx("zero size"); fatalx("xmalloc: zero size");
if ((ptr = malloc(size)) == NULL) if ((ptr = malloc(size)) == NULL)
fatal("xmalloc failed"); log_fatal("xmalloc: allocating %zu bytes", size);
return (ptr); return (ptr);
} }
@ -71,9 +66,9 @@ xrealloc(void *oldptr, size_t newsize)
void *newptr; void *newptr;
if (newsize == 0) if (newsize == 0)
fatalx("zero size"); fatalx("xrealloc: zero size");
if ((newptr = realloc(oldptr, newsize)) == NULL) if ((newptr = realloc(oldptr, newsize)) == NULL)
fatal("xrealloc failed"); log_fatal("xrealloc: allocating %zu bytes", newsize);
return (newptr); return (newptr);
} }
@ -81,15 +76,13 @@ xrealloc(void *oldptr, size_t newsize)
void * void *
xreallocarray(void *oldptr, size_t nmemb, size_t size) xreallocarray(void *oldptr, size_t nmemb, size_t size)
{ {
size_t newsize = nmemb * size;
void *newptr; void *newptr;
if (newsize == 0) if (nmemb == 0 || size == 0)
fatalx("zero size"); fatalx("xreallocarray: zero size");
if (SIZE_MAX / nmemb < size) if ((newptr = reallocarray(oldptr, nmemb, size)) == NULL)
fatalx("nmemb * size > SIZE_MAX"); log_fatal("xreallocarray: allocating %zu * %zu bytes",
if ((newptr = realloc(oldptr, newsize)) == NULL) nmemb, size);
fatal("xreallocarray failed");
return (newptr); return (newptr);
} }
@ -114,7 +107,7 @@ xvasprintf(char **ret, const char *fmt, va_list ap)
i = vasprintf(ret, fmt, ap); i = vasprintf(ret, fmt, ap);
if (i < 0 || *ret == NULL) if (i < 0 || *ret == NULL)
fatal("xvasprintf failed"); fatal("xvasprintf");
return (i); return (i);
} }
@ -138,11 +131,11 @@ xvsnprintf(char *buf, size_t len, const char *fmt, va_list ap)
int i; int i;
if (len > INT_MAX) if (len > INT_MAX)
fatalx("len > INT_MAX"); fatalx("xvsnprintf: len > INT_MAX");
i = vsnprintf(buf, len, fmt, ap); i = vsnprintf(buf, len, fmt, ap);
if (i < 0) if (i < 0 || i >= (int)len)
fatal("vsnprintf failed"); fatalx("xvsnprintf: overflow");
return (i); return (i);
} }