Skip to content
Open
4 changes: 2 additions & 2 deletions src/cmd/builtin/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ dialogue(Sfio_t* mp, Sfio_t* lp, int delay, int timeout)
{
int op;
int line;
int n;
intmax_t n;
char* s;
char* m;
char* e;
Expand Down Expand Up @@ -919,7 +919,7 @@ dialogue(Sfio_t* mp, Sfio_t* lp, int delay, int timeout)
match(s, m, 1);
break;
case 's':
n = (int)strtol(s, &e, 0);
n = strtoll(s, &e, 0);
if (*e)
error(2, "%s: invalid delay -- milliseconds expected", s);
if (n)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libast/comp/wordexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2026 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -45,7 +45,7 @@ static int sh_unquote(char* string)
return sp-string;
if((dp=sp) > string && sp[-1]=='$')
{
int n=stresc(sp+1);
ptrdiff_t n=stresc(sp+1);
/* copy all but trailing ' */
while(--n>0)
*dp++ = *++sp;
Expand Down
71 changes: 20 additions & 51 deletions src/lib/libast/disc/sfkeyprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* Copyright (c) 2020-2026 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand All @@ -14,6 +14,7 @@
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* Martijn Dekker <martijn@inlv.org> *
* Johnothan King <johnothanking@protonmail.com> *
* *
***********************************************************************/

Expand Down Expand Up @@ -50,8 +51,8 @@ typedef struct
typedef struct
{
char* next;
int delimiter;
int first;
char delimiter;
} Field_t;

typedef union
Expand All @@ -72,9 +73,9 @@ getfield(Field_t* f, int restore)
{
char* s;
int n;
int c;
int lp;
int rp;
char c;
char lp;
char rp;
char* b;

if (!f->delimiter)
Expand Down Expand Up @@ -150,9 +151,9 @@ getfmt(Sfio_t* sp, void* vp, Sffmt_t* dp)

NOT_USED(sp);
fp->level++;
if (fp->fmt.t_str && fp->fmt.n_str > 0 && (v = fmtbuf(fp->fmt.n_str + 1)))
if (fp->fmt.t_str && fp->fmt.n_str > 0 && (v = fmtbuf((size_t)(fp->fmt.n_str + 1))))
{
memcpy(v, fp->fmt.t_str, fp->fmt.n_str);
memcpy(v, fp->fmt.t_str, (size_t)fp->fmt.n_str);
v[fp->fmt.n_str] = 0;
b = v;
for (;;)
Expand Down Expand Up @@ -190,7 +191,7 @@ getfmt(Sfio_t* sp, void* vp, Sffmt_t* dp)
x = FMT_case;
else if (streq(a, "edit"))
x = FMT_edit;
*(a + 4) = d;
*(a + 4) = (char)d;
if (x)
a = 0;
}
Expand All @@ -203,7 +204,7 @@ getfmt(Sfio_t* sp, void* vp, Sffmt_t* dp)
h = (*fp->lookup)(fp->handle, &fp->fmt, a, &s, &n);
fp->fmt.t_str = t;
if (i)
*v++ = i;
*v++ = (char)i;
}
else
{
Expand All @@ -214,7 +215,7 @@ getfmt(Sfio_t* sp, void* vp, Sffmt_t* dp)
switch (fp->fmt.fmt)
{
case 'c':
value->c = s ? *s : n;
value->c = s ? *s : (char)n;
break;
case 'd':
case 'i':
Expand Down Expand Up @@ -262,20 +263,20 @@ getfmt(Sfio_t* sp, void* vp, Sffmt_t* dp)

fmt = *fp;
fmt.fmt.form = v;
for (h = 0; h < elementsof(fmt.tmp); h++)
for (h = 0; h < (ssize_t)elementsof(fmt.tmp); h++)
fmt.tmp[h] = 0;
if (!fp->tmp[0] && !(fp->tmp[0] = sfstropen()) || sfprintf(fp->tmp[0], "%!", &fmt) <= 0 || !(s = sfstruse(fp->tmp[0])))
s = "";
*(v - 1) = d;
*(v - 1) = (char)d;
if (f.delimiter)
*f.next = d;
for (h = 0; h < elementsof(fmt.tmp); h++)
*f.next = (char)d;
for (h = 0; h < (ssize_t)elementsof(fmt.tmp); h++)
if (fmt.tmp[h])
sfclose(fmt.tmp[h]);
h = 1;
break;
}
*(v - 1) = d;
*(v - 1) = (char)d;
}
break;
case FMT_edit:
Expand Down Expand Up @@ -317,7 +318,7 @@ getfmt(Sfio_t* sp, void* vp, Sffmt_t* dp)
value->s = "\n";
break;
case '.':
value->i = n;
value->i = (int)n;
break;
default:
if ((!fp->convert || !(value->s = (*fp->convert)(fp->handle, &fp->fmt, a, s, n))) && (!fp->tmp[0] && !(fp->tmp[0] = sfstropen()) || sfprintf(fp->tmp[0], "%%%c", fp->fmt.fmt) <= 0 || !(value->s = sfstruse(fp->tmp[0]))))
Expand All @@ -332,13 +333,11 @@ getfmt(Sfio_t* sp, void* vp, Sffmt_t* dp)
* this is the original interface
*/

#undef sfkeyprintf

int
ssize_t
sfkeyprintf(Sfio_t* sp, void* handle, const char* format, Sf_key_lookup_t lookup, Sf_key_convert_t convert)
{
int i;
int r;
size_t i;
ssize_t r;
Fmt_t fmt;

memset(&fmt, 0, sizeof(fmt));
Expand All @@ -357,33 +356,3 @@ sfkeyprintf(Sfio_t* sp, void* handle, const char* format, Sf_key_lookup_t lookup
regfree(fmt.re[i]);
return r;
}

#undef _AST_API_H

#include <ast_api.h>

/*
* Sffmt_t* callback args
*/

int
sfkeyprintf_20000308(Sfio_t* sp, void* handle, const char* format, Sf_key_lookup_t lookup, Sf_key_convert_t convert)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're deleting the wrong version here. The sfkeyprintf version is currently used by one thing in the code base, the pids built-in command, and if I'm not mistaken, the API logic causes this version to be used and not the old/"original" one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're incorrect. Patch the 'original' sfkeyprintf on the dev branch to use abort():

diff --git a/src/lib/libast/disc/sfkeyprintf.c b/src/lib/libast/disc/sfkeyprintf.c
index 91c4d6806..26d4cbd19 100644
--- a/src/lib/libast/disc/sfkeyprintf.c
+++ b/src/lib/libast/disc/sfkeyprintf.c
@@ -355,6 +355,7 @@ sfkeyprintf(Sfio_t* sp, void* handle, const char* format, Sf_key_lookup_t lookup
 	for (i = 0; i < elementsof(fmt.re); i++)
 		if (fmt.re[i])
 			regfree(fmt.re[i]);
+	abort();
 	return r;
 }
 
$ bin/package use
«0»8:~/GitRepos/KornShell/ksh[dev] $ pids
PID=231169 PPID=222248 PGID=231169 TID=231169 SID=-1Abort(coredump)

{
int i;
int r;
Fmt_t fmt;

memset(&fmt, 0, sizeof(fmt));
fmt.version = 20030909;
fmt.fmt.version = SFIO_VERSION;
fmt.fmt.form = (char*)format;
fmt.fmt.extf = getfmt;
fmt.handle = handle;
fmt.lookup = lookup;
fmt.convert = convert;
r = sfprintf(sp, "%!", &fmt) - fmt.invisible;
for (i = 0; i < elementsof(fmt.tmp); i++)
if (fmt.tmp[i])
sfclose(fmt.tmp[i]);
return r;
}
4 changes: 0 additions & 4 deletions src/lib/libast/features/api
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ api ast 20120528 regexec regnexec regsubexec

api ast 20120411 cmdopen

api ast 20110505 cmdopen

api ast 20100601 pathaccess pathcanon pathcat pathpath pathrepl

api ast 20000308 sfkeyprintf

print #define _AST_VERSION AST_VERSION /* pre-20100601 compatibility */
8 changes: 4 additions & 4 deletions src/lib/libast/include/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ extern char* fmtesq(const char*, const char*);
extern char* fmtident(const char*);
extern char* fmtip4(uint32_t, int);
extern char* fmtfmt(const char*);
extern char* fmtgid(int);
extern char* fmtgid(gid_t);
extern char* fmtint(intmax_t, int);
extern char* fmtmatch(const char*);
extern char* fmtmode(mode_t, int);
Expand All @@ -339,7 +339,7 @@ extern char* fmtre(const char*);
extern char* fmtscale(Sfulong_t, unsigned int);
extern char* fmtsignal(int);
extern char* fmttime(const char*, time_t);
extern char* fmtuid(int);
extern char* fmtuid(uid_t);
extern void* memdup(const void*, size_t);
extern size_t memhash(const void*, int);
extern unsigned long memsum(const void*, int, unsigned long);
Expand Down Expand Up @@ -369,8 +369,8 @@ extern char* setenviron(const char*);
extern pid_t spawnveg(const char*, char* const[], char* const[], pid_t, int);
extern char* strcopy(char*, const char*);
extern unsigned long strelapsed(const char*, char**, int);
extern int stresc(char*);
extern int strexp(char*, int);
extern ptrdiff_t stresc(char*);
extern ptrdiff_t strexp(char*, int);
extern long streval(const char*, char**, long(*)(const char*, char**));
extern long strexpr(const char*, char**, long(*)(const char*, char**, void*), void*);
extern int strgid(const char*);
Expand Down
33 changes: 16 additions & 17 deletions src/lib/libast/include/cmdarg.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* Copyright (c) 2020-2026 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -31,20 +31,20 @@

#define CMD_VERSION 20120411L

#define CMD_CHECKED (1<<9) /* cmdopen() argv[0] ok */
#define CMD_EMPTY (1<<0) /* run once, even if no args */
#define CMD_EXACT (1<<1) /* last command must have argmax*/
#define CMD_EXIT (1<<11) /* fatal error_info.exit() */
#define CMD_IGNORE (1<<2) /* ignore EXIT_QUIT exit */
#define CMD_INSERT (1<<3) /* argpat for insertion */
#define CMD_MINIMUM (1<<4) /* argmax is a minimum */
#define CMD_NEWLINE (1<<5) /* echo separator is newline */
#define CMD_POST (1<<6) /* argpat is post arg position */
#define CMD_QUERY (1<<7) /* trace and query each command */
#define CMD_SILENT (1<<10) /* no error messages */
#define CMD_TRACE (1<<8) /* trace each command */
#define CMD_CHECKED (1U<<9) /* cmdopen() argv[0] ok */
#define CMD_EMPTY (1U<<0) /* run once, even if no args */
#define CMD_EXACT (1U<<1) /* last command must have argmax*/
#define CMD_EXIT (1U<<11) /* fatal error_info.exit() */
#define CMD_IGNORE (1U<<2) /* ignore EXIT_QUIT exit */
#define CMD_INSERT (1U<<3) /* argpat for insertion */
#define CMD_MINIMUM (1U<<4) /* argmax is a minimum */
#define CMD_NEWLINE (1U<<5) /* echo separator is newline */
#define CMD_POST (1U<<6) /* argpat is post arg position */
#define CMD_QUERY (1U<<7) /* trace and query each command */
#define CMD_SILENT (1U<<10) /* no error messages */
#define CMD_TRACE (1U<<8) /* trace each command */

#define CMD_USER (1<<12)
#define CMD_USER (1U<<12)

#define CMDDISC(d,f,e) (memset(d,0,sizeof(*(d))),(d)->version=CMD_VERSION,(d)->flags=(f),(d)->errorf=(e))

Expand Down Expand Up @@ -72,10 +72,9 @@ typedef struct Cmdarg_s /* cmdopen() handle */
} Cmdarg_t;

#ifndef cmdopen
extern Cmdarg_t* cmdopen(char**, int, int, const char*, int);
extern Cmdarg_t* cmdopen(char**, int, ssize_t, const char*, uint32_t);
#endif
extern Cmdarg_t* cmdopen_20110505(char**, int, int, const char*, int, Error_f);
extern Cmdarg_t* cmdopen_20120411(char**, int, int, const char*, Cmddisc_t*);
extern Cmdarg_t* cmdopen_20120411(char**, int, ssize_t, const char*, Cmddisc_t*);
extern int cmdflush(Cmdarg_t*);
extern int cmdarg(Cmdarg_t*, const char*, int);
extern int cmdclose(Cmdarg_t*);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/libast/include/sfdisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* Copyright (c) 2020-2026 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand All @@ -14,6 +14,7 @@
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* Martijn Dekker <martijn@inlv.org> *
* Johnothan King <johnothanking@protonmail.com> *
* *
***********************************************************************/
/*
Expand All @@ -38,8 +39,7 @@
typedef int (*Sf_key_lookup_t)(void*, Sffmt_t*, const char*, char**, Sflong_t*);
typedef char* (*Sf_key_convert_t)(void*, Sffmt_t*, const char*, char*, Sflong_t);

extern int sfkeyprintf(Sfio_t*, void*, const char*, Sf_key_lookup_t, Sf_key_convert_t);
extern int sfkeyprintf_20000308(Sfio_t*, void*, const char*, Sf_key_lookup_t, Sf_key_convert_t);
extern ssize_t sfkeyprintf(Sfio_t*, void*, const char*, Sf_key_lookup_t, Sf_key_convert_t);

/*
* pure sfio read and/or write disciplines
Expand Down
9 changes: 5 additions & 4 deletions src/lib/libast/include/swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* Copyright (c) 2020-2026 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand All @@ -14,6 +14,7 @@
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* Martijn Dekker <martijn@inlv.org> *
* Johnothan King <johnothanking@protonmail.com> *
* *
***********************************************************************/
/*
Expand All @@ -36,8 +37,8 @@
#define SWAPOP(n) (((n)&int_swap)^(n))

extern void* swapmem(int, const void*, void*, size_t);
extern intmax_t swapget(int, const void*, int);
extern void* swapput(int, void*, int, intmax_t);
extern int swapop(const void*, const void*, int);
extern intmax_t swapget(int, const void*, size_t);
extern void* swapput(int, void*, size_t, intmax_t);
extern ssize_t swapop(const void*, const void*, ssize_t);

#endif
4 changes: 2 additions & 2 deletions src/lib/libast/man/fmt.3
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ char* fmtdev(struct stat* \fIst\fP);
char* fmtelapsed(unsigned long \fIcount\fP, unsigned long \fIpersec\fP)
char* fmtesc(const char* \fIstring\fP);
char* fmtfs(struct stat* \fIst\fP);
char* fmtgid(int \fIgid\fP);
char* fmtgid(gid_t \fIgid\fP);
char* fmtmatch(const char* \fIre\fP);
char* fmtmode(mode_t \fImode\fP, int \fIexternal\fP);
char* fmtperm(mode_t \fIperm\fP);
char* fmtre(const char* \fIpattern\fP);
char* fmtsignal(int \fIsig\fP);
char* fmttime(const char* \fIformat\fP, time_t \fItm\fP);
char* fmtuid(int \fIuid\fP);
char* fmtuid(uid_t \fIuid\fP);
.EE
.SH DESCRIPTION
These routines return a pointer to a formatted string for various numeric
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/man/regex.3
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void regfree(regex_t* \fIre\fP);

regclass_t regclass(const char* \fIstr\fP, char** \fIend\fP);
int regaddclass(const char* \fIname\fP, regclass_t \fIclassf\fP);
int regcollate(const char* \fIstr\fP, char** \fIend\fP, char* \fIbuf\fP, int \fIsize\fP);
int regcollate(const char* \fIstr\fP, char** \fIend\fP, char* \fIbuf\fP, size_t \fIsize\fP, wchar_t* \fIwchar\fP);

regstat_t* regstat(const regex_t* \fIre\fP);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/man/stresc.3
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
.SH NAME
stresc \- convert character constants in string
.SH SYNOPSIS
.L "int stresc(char* s)"
.L "ptrdiff_t stresc(char* s)"
.SH DESCRIPTION
.I stresc
converts
Expand Down
Loading