-/* $OpenBSD: lex.c,v 1.79 2023/02/08 17:22:10 kn Exp $ */
+/* $OpenBSD: lex.c,v 1.80 2024/04/28 16:43:15 florian Exp $ */
/*
* lexical analysis and source input
case 'd': /* '\' 'd' Dow Mon DD */
time(&t);
tm = localtime(&t);
- strftime(strbuf, sizeof strbuf, "%a %b %d", tm);
+ if (tm)
+ strftime(strbuf, sizeof strbuf,
+ "%a %b %d", tm);
+ else
+ strbuf[0] = '\0';
break;
case 'D': /* '\' 'D' '{' strftime format '}' */
p = strchr(cp + 2, '}');
*p = '\0';
time(&t);
tm = localtime(&t);
- strftime(strbuf, sizeof strbuf, tmpbuf, tm);
+ if (tm)
+ strftime(strbuf, sizeof strbuf, tmpbuf,
+ tm);
+ else
+ strbuf[0] = '\0';
cp = strchr(cp + 2, '}');
break;
case 'e': /* '\' 'e' escape */
case 't': /* '\' 't' 24 hour HH:MM:SS */
time(&t);
tm = localtime(&t);
- strftime(strbuf, sizeof strbuf, "%T", tm);
+ if (tm)
+ strftime(strbuf, sizeof strbuf, "%T",
+ tm);
+ else
+ strbuf[0] = '\0';
break;
case 'T': /* '\' 'T' 12 hour HH:MM:SS */
time(&t);
tm = localtime(&t);
- strftime(strbuf, sizeof strbuf, "%l:%M:%S", tm);
+ if (tm)
+ strftime(strbuf, sizeof strbuf,
+ "%l:%M:%S", tm);
+ else
+ strbuf[0] = '\0';
break;
case '@': /* '\' '@' 12 hour am/pm format */
time(&t);
tm = localtime(&t);
- strftime(strbuf, sizeof strbuf, "%r", tm);
+ if (tm)
+ strftime(strbuf, sizeof strbuf, "%r",
+ tm);
+ else
+ strbuf[0] = '\0';
break;
case 'A': /* '\' 'A' 24 hour HH:MM */
time(&t);
tm = localtime(&t);
- strftime(strbuf, sizeof strbuf, "%R", tm);
+ if (tm)
+ strftime(strbuf, sizeof strbuf, "%R",
+ tm);
+ else
+ strbuf[0] = '\0';
break;
case 'u': /* '\' 'u' username */
strlcpy(strbuf, username, sizeof strbuf);
-/* $OpenBSD: print.c,v 1.88 2024/01/28 19:05:33 deraadt Exp $ */
+/* $OpenBSD: print.c,v 1.89 2024/04/28 16:43:15 florian Exp $ */
/* $NetBSD: print.c,v 1.27 1995/09/29 21:58:12 cgd Exp $ */
/*-
startt = kp->p_ustart_sec;
tp = localtime(&startt);
+ if (tp == NULL) {
+ (void)printf("%-*s", v->width, "-");
+ return;
+ }
if (!now)
(void)time(&now);
if (now - kp->p_ustart_sec < 12 * SECSPERHOUR) {