Skip to content

Commit

Permalink
nvalue sanitisation part 5: remove 'union Value' (re: 0686c70)
Browse files Browse the repository at this point in the history
The last uses of union Value were variables in shell functions in
array.c, name.c and nvdisc.c. These are now converted to use simple
void pointers, with typecasts where necessary for correct
dereference when reading or assigning values.

In most functions, 'union Value *up;' needed to be replaced with a
pointer to a pointer, 'void **vpp', because up was not always
dereferenced. However, in nv_arrayisset() and nv_getnum(), 'up' was
always dereferenced, so a further simplification to 'void *vp' was
possible, removing one layer of dereference.

In array.c, the 'val' member of struct index_array is now an array
of void pointers.

With that, all 'union Value' usage is gone, so the union definition
is deleted from name.h.
  • Loading branch information
McDutchie committed Nov 30, 2024
1 parent c27edcc commit e19063f
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 195 deletions.
19 changes: 0 additions & 19 deletions src/cmd/ksh93/include/name.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,6 @@

#include <ast.h>
#include <cdt.h>

/* Nodes can have all kinds of values */
union Value
{
const char *cp;
int *ip;
int32_t *lp;
pid_t *pidp;
Sflong_t *llp; /* for long long arithmetic */
int16_t *sp;
double *dp; /* for floating point arithmetic */
Sfdouble_t *ldp; /* for long floating point arithmetic */
struct Namval *np; /* for Namval_t node */
union Value *up; /* for indirect node */
struct Ufunction *rp; /* shell user defined functions */
struct Namref *nrp; /* name reference */
void *bfp; /* pointer to built-in command's entry function (typecast to Shbltin_f) */
};

#include "nval.h"

/* used for arrays */
Expand Down
Loading

0 comments on commit e19063f

Please sign in to comment.