Date: Fri, 14 Mar 2014 02:50:33 +0000 (UTC) From: Devin Teske <dteske@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r263137 - head/usr.sbin/bsdconfig/share Message-ID: <201403140250.s2E2oXDo031828@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dteske Date: Fri Mar 14 02:50:32 2014 New Revision: 263137 URL: http://svnweb.freebsd.org/changeset/base/263137 Log: Fix future namespace issues for functions taking $var_to_set -- functions taking a variable to set need to make sure they protect their locals; if $var_to_set positional argument coincides with a local the expected call to `setvar' will fail to reach outside of the function's namespace. When such collisions are experienced (as I did in the rewrite of usermgmt) the solution is to append a full or abbreviated version of the function name to the local (ultimately eliminating collisions). This is rarely needed and only occurs when you have a lot of like-named functions that pass very similar $var_to_set positional arguments to each other (such as-is the case with an expansive library such as `dialog.subr'). Modified: head/usr.sbin/bsdconfig/share/dialog.subr Modified: head/usr.sbin/bsdconfig/share/dialog.subr ============================================================================== --- head/usr.sbin/bsdconfig/share/dialog.subr Fri Mar 14 02:40:52 2014 (r263136) +++ head/usr.sbin/bsdconfig/share/dialog.subr Fri Mar 14 02:50:32 2014 (r263137) @@ -1,6 +1,6 @@ if [ ! "$_DIALOG_SUBR" ]; then _DIALOG_SUBR=1 # -# Copyright (c) 2006-2013 Devin Teske +# Copyright (c) 2006-2014 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -469,16 +469,17 @@ f_dialog_menu_constrain() # Print debug warnings if any given (non-NULL) argument are invalid # NOTE: Don't change the name of $__{var,min,}{height,width,rows} # - local __height __width __rows + local __height_menu_constrain __width_menu_constrain + local __rows_menu_constrain local __arg __cp __fname=f_dialog_menu_constrain for __arg in height width rows; do debug= f_getvar __var_$__arg __cp [ "$__cp" ] || continue - if ! debug= f_getvar "$__cp" __$__arg; then + if ! debug= f_getvar "$__cp" __${__arg}_menu_constrain; then f_dprintf "%s: var_%s variable \`%s' not set" \ $__fname $__arg "$__cp" __retval=$FAILURE - elif ! eval f_isinteger \$__$__arg; then + elif ! eval f_isinteger \$__${__arg}_menu_constrain; then f_dprintf "%s: var_%s variable value not a number" \ $__fname $__arg __retval=$FAILURE @@ -502,9 +503,11 @@ f_dialog_menu_constrain() # Adjust height if desired if [ "$__var_height" ]; then - if [ $__height -lt ${__min_height:-0} ]; then + if [ $__height_menu_constrain -lt ${__min_height:-0} ]; then setvar "$__var_height" $__min_height - elif [ $__height -gt $__max_height_menu_constrain ]; then + elif [ $__height_menu_constrain -gt \ + $__max_height_menu_constrain ] + then setvar "$__var_height" $__max_height_menu_constrain fi fi @@ -516,9 +519,11 @@ f_dialog_menu_constrain() else : ${__min_width:=${DIALOG_MIN_WIDTH:-24}} fi - if [ $__width -lt $__min_width ]; then + if [ $__width_menu_constrain -lt $__min_width ]; then setvar "$__var_width" $__min_width - elif [ $__width -gt $__max_width_menu_constrain ]; then + elif [ $__width_menu_constrain -gt \ + $__max_width_menu_constrain ] + then setvar "$__var_width" $__max_width_menu_constrain fi fi @@ -531,16 +536,20 @@ f_dialog_menu_constrain() : ${__min_rows:=0} fi - local __max_rows=$(( $__max_height_menu_constrain - 7 )) + local __max_rows_menu_constrain=$(( + $__max_height_menu_constrain - 7 + )) # If prompt_len is zero (no prompt), bump the max-rows by 1 # Default assumption is (if no argument) that there's no prompt - [ ${__prompt_len:-0} -gt 0 ] || - __max_rows=$(( $__max_rows + 1 )) + [ ${__prompt_len:-0} -gt 0 ] || __max_rows_menu_constrain=$(( + $__max_rows_menu_constrain + 1 + )) - if [ $__rows -lt $__min_rows ]; then + if [ $__rows_menu_constrain -lt $__min_rows ]; then setvar "$__var_rows" $__min_rows - elif [ $__rows -gt $__max_rows ]; then - setvar "$__var_rows" $__max_rows + elif [ $__rows_menu_constrain -gt $__max_rows_menu_constrain ] + then + setvar "$__var_rows" $__max_rows_menu_constrain fi fi @@ -1100,19 +1109,20 @@ f_dialog_radiolist_size() # longest item-length (both used to bump the width), and the number of # rows (used to bump the height). # - local __longest_tag=0 __longest_item=0 __rows=0 + local __longest_tag=0 __longest_item=0 __rows_rlist_size=0 while [ $# -ge 3 ]; do local __tag="$1" __item="$2" shift 3 # tag/item/status [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} - __rows=$(( $__rows + 1 )) + __rows_rlist_size=$(( $__rows_rlist_size + 1 )) done # Adjust rows early (for up-coming height calculation) if [ "$__var_height" -o "$__var_rows" ]; then # Add a row for visual aid if using Xdialog(1) - [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) + [ "$USE_XDIALOG" ] && + __rows_rlist_size=$(( $__rows_rlist_size + 1 )) fi # Adjust height if desired @@ -1120,10 +1130,12 @@ f_dialog_radiolist_size() # Add rows to height if [ "$USE_XDIALOG" ]; then __height_rlist_size=$(( - $__height_rlist_size + $__rows + 7 )) + $__height_rlist_size + $__rows_rlist_size + 7 + )) else __height_rlist_size=$(( - $__height_rlist_size + $__rows + 4 )) + $__height_rlist_size + $__rows_rlist_size + 4 + )) fi setvar "$__var_height" $__height_rlist_size fi @@ -1140,7 +1152,7 @@ f_dialog_radiolist_size() fi # Store adjusted rows if desired - [ "$__var_rows" ] && setvar "$__var_rows" $__rows + [ "$__var_rows" ] && setvar "$__var_rows" $__rows_rlist_size # Constrain height, width, and rows to sensible minimum/maximum values # Return success if no-constrain, else return status from constrain @@ -1220,20 +1232,26 @@ f_dialog_radiolist_with_help_size() # all used to bump the width -- and the number of rows (used to bump # the height). # - local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0 + local __longest_tag=0 __longest_item=0 __longest_help=0 + local __rows_rlist_with_help_size=0 while [ $# -ge 4 ]; do local __tag="$1" __item="$2" __status="$3" __help="$4" shift 4 # tag/item/status/help [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help} - __rows=$(( $__rows + 1 )) + __rows_rlist_with_help_size=$(( + $__rows_rlist_with_help_size + 1 + )) done # Adjust rows early (for up-coming height calculation) if [ "$__var_height" -o "$__var_rows" ]; then # Add a row for visual aid if using Xdialog(1) - [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) + [ "$USE_XDIALOG" ] && + __rows_rlist_with_help_size=$(( + $__rows_rlist_with_help_size + 1 + )) fi # Adjust height if desired @@ -1241,10 +1259,14 @@ f_dialog_radiolist_with_help_size() # Add rows to height if [ "$USE_XDIALOG" ]; then __height_rlist_with_help_size=$(( - $__height_rlist_with_help_size + $__rows + 7 )) + $__height_rlist_with_help_size + + $__rows_rlist_with_help_size + 7 + )) else __height_rlist_with_help_size=$(( - $__height_rlist_with_help_size + $__rows + 4 )) + $__height_rlist_with_help_size + + $__rows_rlist_with_help_size + 4 + )) fi setvar "$__var_height" $__height fi @@ -1270,7 +1292,7 @@ f_dialog_radiolist_with_help_size() fi # Store adjusted rows if desired - [ "$__var_rows" ] && setvar "$__var_rows" $__rows + [ "$__var_rows" ] && setvar "$__var_rows" $__rows_rlist_with_help_size # Constrain height, width, and rows to sensible minimum/maximum values # Return success if no-constrain, else return status from constrain
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201403140250.s2E2oXDo031828>