mirror of
				git://git.code.sf.net/p/cdesktopenv/code
				synced 2025-03-09 15:50:02 +00:00 
			
		
		
		
	typeset: Correct numeric attribute change for floating points (#163)
This commit resolves the following incorrect variable assignments: $ unset a; typeset -uF a=2; typeset -p a typeset -X a=0x1.0000000000p+1 $ unset a; typeset -Fu a=2; typeset -p a typeset -X a=0x1.0000000000p+1 $ unset a; typeset -ulF a=2; typeset -p a typeset -l -X a=0x1.0000000000p+1 $ unset a; typeset -Ful a=2; typeset -p a typeset -l -X a=0x1.0000000000p+1 $ unset a; typeset -Eu a=2; typeset -p a typeset -E -X a=2 $ unset a; typeset -Eul a=2; typeset -p a typeset -l -E -X a=2 src/cmd/ksh93/bltins/typeset.c: - If the unsigned option (-u) was provided in conjunction with a floating point (-F) then due to a flag collision with NV_UNSIGN and NV_HEXFLOAT both having the value of NV_LTOU caused the floating point to become a hexadecimal floating point (-X) in error. Also, if a -E option flag was followed with a -u option then the resulting variable would be both a scientific notation and a hexadecimal floating point at the same time. src/cmd/ksh93/tests/attributes.sh: - Add regression tests. Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
		
							parent
							
								
									5a2e7dae67
								
							
						
					
					
						commit
						19c427435b
					
				
					 3 changed files with 37 additions and 2 deletions
				
			
		|  | @ -274,6 +274,9 @@ int    b_typeset(int argc,register char *argv[],Shbltin_t *context) | |||
| 					flag &= ~NV_EXPNOTE; | ||||
| 					flag |= NV_HEXFLOAT; | ||||
| 				} | ||||
| 				else | ||||
| 				        /* n=='F' Remove possible collision with NV_UNSIGN/NV_HEXFLOAT */ | ||||
| 				        flag &= ~NV_HEXFLOAT; | ||||
| 				break; | ||||
| 			case 'b': | ||||
| 				flag |= NV_BINARY; | ||||
|  | @ -352,8 +355,11 @@ int    b_typeset(int argc,register char *argv[],Shbltin_t *context) | |||
| 				flag |= NV_TAGGED; | ||||
| 				break; | ||||
| 			case 'u': | ||||
| 				tdata.wctname = e_toupper; | ||||
| 				flag |= NV_LTOU; | ||||
| 			        if(!isfloat) | ||||
| 			        { | ||||
| 				        tdata.wctname = e_toupper; | ||||
| 				        flag |= NV_LTOU; | ||||
| 				} | ||||
| 				break; | ||||
| 			case 'x': | ||||
| 				flag &= ~NV_VARNAME; | ||||
|  |  | |||
|  | @ -587,5 +587,31 @@ got=$(< $tmpfile) | |||
| [[ $got == "$exp" ]] || err_exit 'variable exported in function in a subshell is also visible in a different subshell' \ | ||||
| 	"(expected $(printf %q "$exp"), got $(printf %q "$got"))" | ||||
| 
 | ||||
| # ====== | ||||
| # Combining -u with -F or -E caused an incorrect variable type | ||||
| # https://github.com/ksh93/ksh/pull/163 | ||||
| typeset -A expect=( | ||||
| 	[uF]='typeset -F a=2.0000000000' | ||||
| 	[Fu]='typeset -F a=2.0000000000' | ||||
| 	[ulF]='typeset -l -F a=2.0000000000' | ||||
| 	[Ful]='typeset -l -F a=2.0000000000' | ||||
| 	[Eu]='typeset -E a=2' | ||||
| 	[Eul]='typeset -l -E a=2' | ||||
| ) | ||||
| for flag in "${!expect[@]}" | ||||
| do	unset a | ||||
| 	actual=$( | ||||
| 		redirect 2>&1 | ||||
| 		(typeset "-$flag" a=2; typeset -p a) | ||||
| 		leak=${ typeset -p a; } | ||||
| 		[[ -n $leak ]] && print "SUBSHELL LEAK: $leak" | ||||
| 	) | ||||
| 	if	[[ $actual != "${expect[$flag]}" ]] | ||||
| 	then	err_exit "typeset -$flag a=2:" \ | ||||
| 			"expected $(printf %q "${expect[$flag]}"), got $(printf %q "$actual")" | ||||
| 	fi | ||||
| done | ||||
| unset expect | ||||
| 
 | ||||
| # ====== | ||||
| exit $((Errors<125?Errors:125)) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue