Added check for $(($n))

This commit is contained in:
Vidar Holen 2012-11-15 23:32:45 -08:00
parent ad9db04856
commit a2cc44a04d
1 changed files with 8 additions and 0 deletions

View File

@ -37,6 +37,7 @@ basicChecks = [
,checkBraceExpansionVars
,checkForDecimals
,checkDivBeforeMult
,checkArithmeticDeref
]
modifyMap = modify
@ -252,6 +253,13 @@ checkDivBeforeMult (TA_Binary _ "*" (TA_Binary id "/" _ _) _) = do
addNoteFor id $ Note InfoC $ "Increase precision by replacing a/b*c with a*c/b"
checkDivBeforeMult _ = return ()
prop_checkArithmeticDeref = verify checkArithmeticDeref "echo $((3+$foo))"
prop_checkArithmeticDeref2 = verify checkArithmeticDeref "cow=14; (( s+= $cow ))"
prop_checkArithmeticDeref3 = verifyNot checkArithmeticDeref "cow=1/40; (( s+= ${cow%%/*} ))"
checkArithmeticDeref (TA_Expansion _ (T_DollarBraced id str)) | not $ any (`elem` "/.:#%") $ str =
addNoteFor id $ Note WarningC $ "Don't use $ on variables in (( )) unless you want to dereference twice"
checkArithmeticDeref _ = return ()
allModifiedVariables t = snd $ runState (doAnalysis (\x -> modify $ (++) (getModifiedVariables x)) t) []
--- Subshell detection