From 6a9ca73e10c3c4e8a95101313e9c5d46cf018f86 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 7 Jan 2017 20:31:02 +0000 Subject: Types fix: first pass This pass makes variable size_t-ready, so everything works when the prototypes are fixed in skalibs. Some code uses "unsigned int *" where it should be "size_t *"; it cannot be changed now, but it's been marked with XXX. It must change at the same time as the skalibs API. --- src/libexecline/el_execsequence.c | 2 +- src/libexecline/el_parse.c | 11 ++++---- src/libexecline/el_parse_from_buffer.c | 3 +- src/libexecline/el_popenv.c | 11 ++++---- src/libexecline/el_pushenv.c | 13 +++++---- src/libexecline/el_spawn1.c | 3 +- src/libexecline/el_substandrun.c | 3 +- src/libexecline/el_substandrun_str.c | 3 +- src/libexecline/el_substitute.c | 50 +++++++++++++++++++--------------- src/libexecline/el_transform.c | 21 +++++++------- src/libexecline/el_vardupl.c | 5 ++-- src/libexecline/exlp.c | 16 ++++++----- src/libexecline/exlsn_multidefine.c | 7 +++-- 13 files changed, 83 insertions(+), 65 deletions(-) (limited to 'src/libexecline') diff --git a/src/libexecline/el_execsequence.c b/src/libexecline/el_execsequence.c index 6b825af..d697f2e 100644 --- a/src/libexecline/el_execsequence.c +++ b/src/libexecline/el_execsequence.c @@ -19,8 +19,8 @@ void el_execsequence (char const *const *argv1, char const *const *argv2, char c } else { + size_t j = 2 ; int wstat ; - unsigned int j = 2 ; #ifdef EXECLINE_OLD_VARNAMES char fmt[UINT_FMT * 2 + 15] = "?=" ; #else diff --git a/src/libexecline/el_parse.c b/src/libexecline/el_parse.c index 1544f51..acff34a 100644 --- a/src/libexecline/el_parse.c +++ b/src/libexecline/el_parse.c @@ -1,6 +1,7 @@ /* ISC license. */ -#include +#include +#include #include #include #include @@ -10,7 +11,7 @@ int el_parse (stralloc *sa, el_chargen_func_t_ref next, void *source) { static unsigned char const class[256] = "`aaaaaaaaadaaaaaaaaaaaaaaaaaaaaaafcbffffffffffffjhhhhhhhiifffffffmmmmmmfffffffffffffffffffffeffffggmmmgfffffffkfffkfkfkflffnfoffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ; - static uint16 const table[16][16] = + static uint16_t const table[16][16] = { { 0x0011, 0x4011, 0x0010, 0x0010, 0x0010, 0x0011, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x4091 }, { 0x0000, 0x4000, 0x8001, 0x8003, 0x8003, 0x0005, 0x0010, 0x8403, 0x8403, 0x8403, 0x8403, 0x0010, 0x8403, 0x8403, 0x0100, 0x4080 }, @@ -30,14 +31,14 @@ int el_parse (stralloc *sa, el_chargen_func_t_ref next, void *source) { 0x820f, 0x8001, 0x8001, 0x8003, 0x8003, 0x0005, 0x0010, 0x8403, 0x8403, 0x8403, 0x8403, 0x0010, 0x8403, 0x8403, 0x8001, 0x8001 } } ; - unsigned int mark = 0 ; - unsigned int n = 0 ; + size_t mark = 0 ; + int n = 0 ; unsigned int blevel = 0 ; unsigned char state = 0, base = 10 ; while (state < 0x10) { - uint16 c ; + uint16_t c ; unsigned char cur ; if (!(*next)(&cur, source)) return -1 ; c = table[class[cur]-'`'][state] ; diff --git a/src/libexecline/el_parse_from_buffer.c b/src/libexecline/el_parse_from_buffer.c index 802fe40..83862f3 100644 --- a/src/libexecline/el_parse_from_buffer.c +++ b/src/libexecline/el_parse_from_buffer.c @@ -1,12 +1,13 @@ /* ISC license. */ +#include #include #include #include static int next (unsigned char *c, void *p) { - register int r = buffer_get((buffer *)p, (char *)c, 1) ; + register ssize_t r = buffer_get((buffer *)p, (char *)c, 1) ; if (r < 0) return 0 ; if (!r) *c = 0 ; return 1 ; diff --git a/src/libexecline/el_popenv.c b/src/libexecline/el_popenv.c index 3726506..c0089d0 100644 --- a/src/libexecline/el_popenv.c +++ b/src/libexecline/el_popenv.c @@ -1,18 +1,19 @@ /* ISC license. */ +#include #include #include #include #include #include -int el_popenv (stralloc *sa, char const *const *envp, unsigned int envlen, char const *const *list, unsigned int listlen) +int el_popenv (stralloc *sa, char const *const *envp, size_t envlen, char const *const *list, size_t listlen) { - unsigned int i = 0, salen = sa->len, count = 0 ; + size_t i = 0, salen = sa->len ; + int count = 0 ; for (; i < envlen ; i++) { - unsigned int equal, colon, n ; - unsigned int j = 0 ; + size_t equal, colon, n, j = 0 ; for (; j < listlen ; j++) if (str_start(envp[i], list[j])) break ; if (j == listlen) goto copyit ; j = str_len(list[j]) ; @@ -34,7 +35,7 @@ int el_popenv (stralloc *sa, char const *const *envp, unsigned int envlen, char copyit: if (!stralloc_catb(sa, envp[i], str_len(envp[i]) + 1)) goto err ; } - return (int)count ; + return count ; badenv : errno = EINVAL ; diff --git a/src/libexecline/el_pushenv.c b/src/libexecline/el_pushenv.c index 9b9608d..4ec43bb 100644 --- a/src/libexecline/el_pushenv.c +++ b/src/libexecline/el_pushenv.c @@ -1,18 +1,19 @@ /* ISC license. */ +#include #include #include #include #include #include -int el_pushenv (stralloc *sa, char const *const *envp, unsigned int envlen, char const *const *list, unsigned int listlen) +int el_pushenv (stralloc *sa, char const *const *envp, size_t envlen, char const *const *list, size_t listlen) { - unsigned int i = 0, salen = sa->len, count = 0 ; + size_t i = 0, salen = sa->len ; + int count = 0 ; for (; i < envlen ; i++) { - unsigned int equal, colon ; - unsigned int j = 0 ; + size_t equal, colon, j = 0 ; for (; j < listlen ; j++) if (str_start(envp[i], list[j])) break ; if (j == listlen) goto copyit ; count++ ; @@ -27,8 +28,8 @@ int el_pushenv (stralloc *sa, char const *const *envp, unsigned int envlen, char } else { + size_t n ; char fmt[UINT_FMT+1] = ":" ; - unsigned int n ; if (colon + 1 + uint_scan(envp[i] + colon + 1, &n) != equal) goto copyit ; n = 1 + uint_fmt(fmt+1, n+1) ; if (!stralloc_catb(sa, envp[i], colon)) goto err ; @@ -39,7 +40,7 @@ int el_pushenv (stralloc *sa, char const *const *envp, unsigned int envlen, char copyit: if (!stralloc_catb(sa, envp[i], str_len(envp[i]) + 1)) goto err ; } - return (int)count ; + return count ; badenv : errno = EINVAL ; diff --git a/src/libexecline/el_spawn1.c b/src/libexecline/el_spawn1.c index f84b10a..f434d70 100644 --- a/src/libexecline/el_spawn1.c +++ b/src/libexecline/el_spawn1.c @@ -2,13 +2,14 @@ #include #include +#include #include pid_t el_spawn1 (char const *prog, char const *const *argv, char const *const *envp, int *fd, int w) { if (!argv[0]) { - static char const *const newargv[2] = { "/bin/true", 0 } ; + static char const *const newargv[3] = { EXECLINE_BINPREFIX "exit", "0", 0 } ; return child_spawn1_pipe(newargv[0], newargv, 0, fd, w) ; } else return child_spawn1_pipe(prog, argv, envp, fd, w) ; diff --git a/src/libexecline/el_substandrun.c b/src/libexecline/el_substandrun.c index 11502ea..8b8084a 100644 --- a/src/libexecline/el_substandrun.c +++ b/src/libexecline/el_substandrun.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -8,6 +9,6 @@ void el_substandrun (int argc, char const *const *argv, char const *const *envp, exlsn_t const *info) { satmp.len = 0 ; - if (!env_string(&satmp, argv, (unsigned int)argc)) strerr_diefu1sys(111, "env_string") ; + if (!env_string(&satmp, argv, (size_t)argc)) strerr_diefu1sys(111, "env_string") ; el_substandrun_str(&satmp, 0, envp, info) ; } diff --git a/src/libexecline/el_substandrun_str.c b/src/libexecline/el_substandrun_str.c index 8168287..a935b82 100644 --- a/src/libexecline/el_substandrun_str.c +++ b/src/libexecline/el_substandrun_str.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -9,7 +10,7 @@ #include #include "exlsn.h" -void el_substandrun_str (stralloc *src, unsigned int srcbase, char const *const *envp, exlsn_t const *info) +void el_substandrun_str (stralloc *src, size_t srcbase, char const *const *envp, exlsn_t const *info) { stralloc dst = STRALLOC_ZERO ; register int r = el_substitute(&dst, src->s + srcbase, src->len, info->vars.s, info->values.s, genalloc_s(elsubst_t const, &info->data), genalloc_len(elsubst_t const, &info->data)) ; diff --git a/src/libexecline/el_substitute.c b/src/libexecline/el_substitute.c index a94c16d..9fa2f70 100644 --- a/src/libexecline/el_substitute.c +++ b/src/libexecline/el_substitute.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -9,7 +10,7 @@ typedef struct elsubsu_s elsubsu_t, *elsubsu_t_ref ; struct elsubsu_s { elsubst_t const *subst ; - unsigned int pos ; + size_t pos ; } ; typedef struct subsuinfo_s subsuinfo_t, *subsuinfo_t_ref ; @@ -36,7 +37,7 @@ struct subsuinfo_s #define INVARBR 0x04 #define ACCEPT 0x05 -static int parseword (stralloc *sa, genalloc *list, char const *s, char const *vars, elsubst_t const *substs, unsigned int nsubst) +static ssize_t parseword (stralloc *sa, genalloc *list, char const *s, char const *vars, elsubst_t const *substs, unsigned int nsubst) { static char const class[5] = "\0\\${}" ; static unsigned char const table[6][5] = @@ -49,7 +50,8 @@ static int parseword (stralloc *sa, genalloc *list, char const *s, char const *v { INWORD, INVAR | MARK | KEEPESC, INVARBR | MARK | KEEPESC, INVAR | KEEPESC, INVARBR | KEEPESC } } ; - unsigned int mark = 0, pos = 0, offset = 0, esc = 0, salen = sa->len, listlen = genalloc_len(elsubsu_t, list) ; + size_t mark = 0, offset = 0, esc = 0, salen = sa->len, listlen = genalloc_len(elsubsu_t, list) ; + ssize_t pos = 0 ; unsigned char state = INWORD ; while (state != ACCEPT) @@ -93,7 +95,7 @@ static int parseword (stralloc *sa, genalloc *list, char const *s, char const *v state = c & STATE ; pos++ ; } sa->len-- ; - return (int)pos ; + return pos ; err: sa->len = salen ; @@ -101,23 +103,23 @@ err: return -1 ; } -static int substword (subsuinfo_t *info, unsigned int wordstart, unsigned int wordlen, unsigned int n, unsigned int offset) +static int substword (subsuinfo_t *info, size_t wordstart, size_t wordlen, unsigned int n, size_t offset) { if (n < genalloc_len(elsubsu_t, &info->list)) { elsubsu_t *list = genalloc_s(elsubsu_t, &info->list) ; char const *p = info->values + list[n].subst->value ; - unsigned int l = list[n].pos + offset ; - unsigned int dstbase = info->dst.len ; - unsigned int sabase = info->sa.len ; + size_t l = list[n].pos + offset ; + size_t dstbase = info->dst.len ; + size_t sabase = info->sa.len ; unsigned int i = 0 ; int nc = 0 ; if (!stralloc_readyplus(&info->sa, l)) return -1 ; stralloc_catb(&info->sa, info->sa.s + wordstart, l) ; - for ( ; i < list[n].subst->n ; i++) + for (; i < list[n].subst->n ; i++) { + size_t plen = str_len(p) ; int r ; - unsigned int plen = str_len(p) ; info->sa.len = sabase + l ; if (!stralloc_readyplus(&info->sa, plen + wordlen - l)) goto err ; stralloc_catb(&info->sa, p, plen) ; @@ -142,33 +144,37 @@ static int substword (subsuinfo_t *info, unsigned int wordstart, unsigned int wo } } -int el_substitute (stralloc *dst, char const *src, unsigned int len, char const *vars, char const *values, elsubst_t const *substs, unsigned int nsubst) +int el_substitute (stralloc *dst, char const *src, size_t len, char const *vars, char const *values, elsubst_t const *substs, unsigned int nsubst) { subsuinfo_t info = SUBSUINFO_ZERO ; - unsigned int nc = 0 ; - unsigned int i = 0 ; - unsigned int dstbase = dst->len ; + size_t i = 0 ; + size_t dstbase = dst->len ; + int nc = 0 ; int wasnull = !dst->s ; + info.dst = *dst ; info.values = values ; while (i < len) { - int r ; genalloc_setlen(elsubsu_t, &info.list, 0) ; info.sa.len = 0 ; - r = parseword(&info.sa, &info.list, src + i, vars, substs, nsubst) ; - if (r < 0) goto err ; - i += r ; - r = substword(&info, 0, info.sa.len, 0, 0) ; - if (r < 0) goto err ; - nc += r ; + { + ssize_t r = parseword(&info.sa, &info.list, src + i, vars, substs, nsubst) ; + if (r < 0) goto err ; + i += r ; + } + { + int r = substword(&info, 0, info.sa.len, 0, 0) ; + if (r < 0) goto err ; + nc += r ; + } } genalloc_free(elsubsu_t, &info.list) ; stralloc_free(&info.sa) ; if (!wasnull) stralloc_free(dst) ; *dst = info.dst ; - return (int)nc ; + return nc ; err : genalloc_free(elsubsu_t, &info.list) ; diff --git a/src/libexecline/el_transform.c b/src/libexecline/el_transform.c index ac84d1d..210cbdf 100644 --- a/src/libexecline/el_transform.c +++ b/src/libexecline/el_transform.c @@ -1,14 +1,15 @@ /* ISC license. */ +#include #include #include #include #include #include -static void el_crunch (stralloc *sa, unsigned int base, char const *delim) +static void el_crunch (stralloc *sa, size_t base, char const *delim) { - register unsigned int i = base, j = base ; + register size_t i = base, j = base ; register int crunching = 0 ; for (; i < sa->len ; i++) { @@ -23,10 +24,10 @@ static void el_crunch (stralloc *sa, unsigned int base, char const *delim) sa->len = j ; } -static int el_split (stralloc *sa, unsigned int base, eltransforminfo_t const *si, int chomped) +static int el_split (stralloc *sa, size_t base, eltransforminfo_t const *si, int chomped) { - unsigned int n = 0 ; - register unsigned int i = base ; + int n = 0 ; + register size_t i = base ; for (; i < sa->len ; i++) if (si->delim[str_chr(si->delim, sa->s[i])]) { @@ -44,13 +45,13 @@ static int el_split (stralloc *sa, unsigned int base, eltransforminfo_t const *s return n ; } -static int el_splitnetstring (stralloc *sa, unsigned int base) +static int el_splitnetstring (stralloc *sa, size_t base) { - unsigned int tmpbase = satmp.len ; - unsigned int n = 0, i = base ; + size_t tmpbase = satmp.len, i = base ; + int n = 0 ; while (i < sa->len) { - register int r = netstring_decode(&satmp, sa->s + i, sa->len - i) ; + register ssize_t r = netstring_decode(&satmp, sa->s + i, sa->len - i) ; if (r < 0) goto err ; if (!stralloc_0(&satmp)) goto err ; i += r ; n++ ; @@ -69,7 +70,7 @@ err: return -1 ; } -int el_transform (stralloc *sa, unsigned int i, eltransforminfo_t const *si) +int el_transform (stralloc *sa, size_t i, eltransforminfo_t const *si) { int chomped = 0 ; if (si->crunch && *si->delim) el_crunch(sa, i, si->delim) ; diff --git a/src/libexecline/el_vardupl.c b/src/libexecline/el_vardupl.c index 7583669..279e79d 100644 --- a/src/libexecline/el_vardupl.c +++ b/src/libexecline/el_vardupl.c @@ -1,11 +1,12 @@ /* ISC license. */ +#include #include #include -int el_vardupl (char const *key, char const *s, unsigned int len) +int el_vardupl (char const *key, char const *s, size_t len) { - register unsigned int i = 0 ; + register size_t i = 0 ; for (; i < len ; i += str_len(s + i) + 1) if (!str_diff(key, s + i)) return 1 ; return 0 ; diff --git a/src/libexecline/exlp.c b/src/libexecline/exlp.c index 060eb68..1ba37c0 100644 --- a/src/libexecline/exlp.c +++ b/src/libexecline/exlp.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -11,13 +12,14 @@ int exlp (unsigned int nmin, char const *const *envp, exlsn_t *info) { - unsigned int varbase = info->vars.len ; - unsigned int valbase = info->values.len ; - unsigned int datbase = genalloc_len(elsubst_t, &info->data) ; - unsigned int i = 0 ; - char const *x = env_get2(envp, "#") ; + size_t varbase = info->vars.len ; + size_t valbase = info->values.len ; + size_t datbase = genalloc_len(elsubst_t, &info->data) ; + size_t poszero ; elsubst_t blah ; - unsigned int n, ntot, poszero ; + char const *x = env_get2(envp, "#") ; + unsigned int n, ntot, i = 0 ; + if (!x) return -2 ; if (!uint0_scan(x, &n)) return -2 ; if (el_vardupl("#", info->vars.s, info->vars.len)) return -2 ; @@ -47,7 +49,7 @@ int exlp (unsigned int nmin, char const *const *envp, exlsn_t *info) for (; i <= ntot ; i++) { char fmt[UINT_FMT] ; - unsigned int l = uint_fmt(fmt, i) ; + size_t l = uint_fmt(fmt, i) ; fmt[l] = 0 ; if (el_vardupl(fmt, info->vars.s, info->vars.len)) goto err2 ; x = (i <= n) ? env_get2(envp, fmt) : "" ; diff --git a/src/libexecline/exlsn_multidefine.c b/src/libexecline/exlsn_multidefine.c index e64cbfd..9c5e248 100644 --- a/src/libexecline/exlsn_multidefine.c +++ b/src/libexecline/exlsn_multidefine.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -11,9 +12,9 @@ int exlsn_multidefine (int argc, char const **argv, char const *const *envp, exl { eltransforminfo_t si = ELTRANSFORMINFO_ZERO ; subgetopt_t localopt = SUBGETOPT_ZERO ; - unsigned int varbase = info->vars.len ; - unsigned int valbase = info->values.len ; - unsigned int pos = valbase ; + size_t varbase = info->vars.len ; + size_t valbase = info->values.len ; + size_t pos = valbase ; unsigned int i = 0 ; unsigned int max ; char const *x ; -- cgit v1.2.3