From 95f99a1f077074ed3ddb924cc3c397d0e33b63b6 Mon Sep 17 00:00:00 2001 From: Ron Sluiter Date: Thu, 10 May 2007 20:14:21 +0000 Subject: [PATCH] Fix for motorUtilInit()'s PVNAME_SZ error check using an uninitialized variable. --- motorApp/MotorSrc/motorUtil.cc | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/motorApp/MotorSrc/motorUtil.cc b/motorApp/MotorSrc/motorUtil.cc index 32e44a63..3d005dac 100644 --- a/motorApp/MotorSrc/motorUtil.cc +++ b/motorApp/MotorSrc/motorUtil.cc @@ -2,9 +2,9 @@ FILENAME... motorUtil.cc USAGE... Motor Record Utility Support. -Version: $Revision: 1.2 $ -Modified By: $Author: peterd $ -Last Modified: $Date: 2007-02-02 13:58:58 $ +Version: $Revision: 1.3 $ +Modified By: $Author: sluiter $ +Last Modified: $Date: 2007-05-10 20:14:21 $ */ @@ -19,6 +19,13 @@ Last Modified: $Date: 2007-02-02 13:58:58 $ * Argonne National Laboratory * * Current Author: Ron Sluiter +* +* Modification Log: +* ----------------- +* .01 05-10-07 rls - Bug fix for motorUtilInit()'s PVNAME_SZ error check using +* an uninitialized variable. +* - Added redundant initialization error check. +* */ #include @@ -81,14 +88,22 @@ static chid chid_allstop, chid_moving, chid_alldone; RTN_STATUS motorUtilInit(char *vme_name) { RTN_STATUS status = OK; + static bool initialized = false; /* motorUtil initialized indicator. */ - if (strlen(vme) > PVNAME_SZ - 7 ) + if (initialized == true) { - printf( "motorUtilInit: Prefix %s has more than %d characters. Exiting", + printf( "motorUtil already initialized. Exiting\n"); + return ERROR; + } + + if (strlen(vme_name) > PVNAME_SZ - 7 ) + { + printf( "motorUtilInit: Prefix %s has more than %d characters. Exiting\n", vme_name, PVNAME_SZ - 7 ); return ERROR; } + initialized = true; vme = epicsStrDup(vme_name); epicsThreadCreate((char *) "motorUtil", epicsThreadPriorityMedium,