mirror of
				git://git.code.sf.net/p/cdesktopenv/code
				synced 2025-03-09 15:50:02 +00:00 
			
		
		
		
	Fix floating point numerics having precision of 0 with assignments (#149)
Issuing typeset floating point numerics having a precision of 0
failed as the precision/size was being overwritten with the string
length of the value, e.g. 'typeset -F0 x=5.67' would result in
'typeset -F 4 x=5.6700' as len('5.67') is 4.
src/cmd/ksh93/include/nval.h:
- Created a symbolic name of NV_FLTSIZEZERO to respresent a float
  having a precision/size of 0. NV_FLTSIZEZERO needs to be a
  negative value.
src/cmd/ksh93/bltins/typeset.c:
- In b_typeset(), added code to set tdata.argnum to NV_FLTSIZEZERO
  for E, F, X options.
- In setall(), adjusted code to allow for tp->argnum to be negative.
src/cmd/ksh93/sh/name.c: nv_newattr():
- Adjusted option value only change code to handle NV_FLTSIZEZERO as
  well as changed to directly setting np->nvsize instead of using
  nv_setsize(np,size) as nv_setsize might contain conflicting and/or
  redundant code.
- Added missing conditional check of '!(newatts&NV_INTEGER)' to
  constrain the size==0 code block to justified strings as
  NV_LJUST, NV_RJUST, or NV_ZFILL are only valid for strings if
  NV_INTEGER is not set. This code block was mistakenly setting
  the precision/size value to the length of the value of an
  assignment for floats whereas it should only be performing
  auto assignment length for justified strings.
			
			
This commit is contained in:
		
							parent
							
								
									95fe07d869
								
							
						
					
					
						commit
						88a6baa1a7
					
				
					 6 changed files with 27 additions and 5 deletions
				
			
		
							
								
								
									
										6
									
								
								NEWS
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								NEWS
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh
 | 
			
		|||
 | 
			
		||||
Any uppercase BUG_* names are modernish shell bug IDs.
 | 
			
		||||
 | 
			
		||||
2020-10-22:
 | 
			
		||||
 | 
			
		||||
- Fixed: 'typeset -F0', 'typeset -E0', and 'typeset -X0' floating point
 | 
			
		||||
  numerics having a precision of 0 with variable assignment.
 | 
			
		||||
  'typeset -F0 x; x=4.56' worked but not 'typeset -F0 x=4.56'.
 | 
			
		||||
 | 
			
		||||
2020-10-21:
 | 
			
		||||
 | 
			
		||||
- Fixed: More concisely correct the exporting of uppercase and lowercase
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -262,6 +262,8 @@ int    b_typeset(int argc,register char *argv[],Shbltin_t *context)
 | 
			
		|||
			case 'X':
 | 
			
		||||
				if(!opt_info.arg || (tdata.argnum = opt_info.num) <0)
 | 
			
		||||
					tdata.argnum = (n=='X'?2*sizeof(Sfdouble_t):10);
 | 
			
		||||
				else if (tdata.argnum==0)
 | 
			
		||||
					tdata.argnum = NV_FLTSIZEZERO;
 | 
			
		||||
				isfloat = 1;
 | 
			
		||||
				if(n=='E')
 | 
			
		||||
				{
 | 
			
		||||
| 
						 | 
				
			
			@ -797,7 +799,7 @@ static int     setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
 | 
			
		|||
					errormsg(SH_DICT,ERROR_exit(1),e_readonly,nv_name(np));
 | 
			
		||||
				newflag = curflag & ~flag;
 | 
			
		||||
			}
 | 
			
		||||
			if (tp->aflag && (tp->argnum>0 || (curflag!=newflag)))
 | 
			
		||||
			if (tp->aflag && (tp->argnum || (curflag!=newflag)))
 | 
			
		||||
			{
 | 
			
		||||
				if(shp->subshell)
 | 
			
		||||
					sh_assignok(np,2);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -165,6 +165,7 @@ struct Namval
 | 
			
		|||
#define NV_DOUBLE	(NV_INTEGER|NV_ZFILL)	/* for floating point */
 | 
			
		||||
#define NV_EXPNOTE	(NV_LJUST)	/* for scientific notation */
 | 
			
		||||
#define NV_HEXFLOAT	(NV_LTOU)	/* for C99 base16 float notation */
 | 
			
		||||
#define NV_FLTSIZEZERO	-1		/* a float with size of 0 being <0 */
 | 
			
		||||
 | 
			
		||||
/*  options for nv_open */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,4 +17,4 @@
 | 
			
		|||
*                  David Korn <dgk@research.att.com>                   *
 | 
			
		||||
*                                                                      *
 | 
			
		||||
***********************************************************************/
 | 
			
		||||
#define SH_RELEASE	"93u+m 2020-10-21"
 | 
			
		||||
#define SH_RELEASE	"93u+m 2020-10-22"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2963,12 +2963,16 @@ void nv_newattr (register Namval_t *np, unsigned newatts, int size)
 | 
			
		|||
	oldsize = nv_size(np);
 | 
			
		||||
	if((size==oldsize|| (n&NV_INTEGER)) && !trans && ((n^newatts)&~NV_NOCHANGE)==0)
 | 
			
		||||
	{
 | 
			
		||||
		if(size)
 | 
			
		||||
			nv_setsize(np,size);
 | 
			
		||||
		if(size>0)
 | 
			
		||||
			np->nvsize = size;
 | 
			
		||||
		else if(size==NV_FLTSIZEZERO)
 | 
			
		||||
			np->nvsize = 0;
 | 
			
		||||
		nv_offattr(np, ~NV_NOFREE);
 | 
			
		||||
		nv_onattr(np, newatts);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	if(size==NV_FLTSIZEZERO)
 | 
			
		||||
		size = 0;
 | 
			
		||||
	/* for an array, change all the elements */
 | 
			
		||||
	if((ap=nv_arrayptr(np)) && ap->nelem>0)
 | 
			
		||||
		nv_putsub(np,NIL(char*),ARRAY_SCAN);
 | 
			
		||||
| 
						 | 
				
			
			@ -3019,7 +3023,7 @@ void nv_newattr (register Namval_t *np, unsigned newatts, int size)
 | 
			
		|||
				if(ap)
 | 
			
		||||
					ap->nelem |= ARRAY_SCAN;
 | 
			
		||||
			}
 | 
			
		||||
			if(size==0 && (newatts&NV_HOST)!=NV_HOST && (newatts&(NV_LJUST|NV_RJUST|NV_ZFILL)))
 | 
			
		||||
			if(size==0 && !(newatts&NV_INTEGER) && (newatts&NV_HOST)!=NV_HOST && (newatts&(NV_LJUST|NV_RJUST|NV_ZFILL)))
 | 
			
		||||
				size = n;
 | 
			
		||||
		}
 | 
			
		||||
		else if(!trans)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -232,5 +232,14 @@ do	tf=$i
 | 
			
		|||
done
 | 
			
		||||
unset i tf pf
 | 
			
		||||
 | 
			
		||||
unset x
 | 
			
		||||
[[ $(typeset -F 0 x=5.67; typeset -p x) == 'typeset -F 0 x=6' ]] || err_exit 'typeset -F 0 with assignment failed to round.'
 | 
			
		||||
[[ $(typeset -E 0 x=5.67; typeset -p x) == 'typeset -E 0 x=6' ]] || err_exit 'typeset -E 0 with assignment failed to round.'
 | 
			
		||||
[[ $(typeset -X 0 x=5.67; typeset -p x) == 'typeset -X 0 x=0x1p+2' ]] || err_exit 'typeset -X 0 with assignment failed to round.'
 | 
			
		||||
 | 
			
		||||
[[ $(typeset -lF 0 x=5.67; typeset -p x) == 'typeset -l -F 0 x=6' ]] || err_exit 'typeset -lF 0 with assignment failed to round.'
 | 
			
		||||
[[ $(typeset -lE 0 x=5.67; typeset -p x) == 'typeset -l -E 0 x=6' ]] || err_exit 'typeset -lE 0 with assignment failed to round.'
 | 
			
		||||
[[ $(typeset -lX 0 x=5.67; typeset -p x) == 'typeset -l -X 0 x=0x1p+2' ]] || err_exit 'typeset -lX 0 with assignment failed to round.'
 | 
			
		||||
 | 
			
		||||
# ======
 | 
			
		||||
exit $((Errors<125?Errors:125))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue