strcpy => styrcpy (shuts up purify)

This commit is contained in:
Jeff Hill
1996-11-02 01:24:49 +00:00
parent c25f195f08
commit 31b046e108
6 changed files with 137 additions and 26 deletions
+13 -1
View File
@@ -5,6 +5,9 @@
// $Id$
//
// $Log$
// Revision 1.3 1996/08/22 21:05:37 jbk
// More fixes to make strings and fixed string work better.
//
// Revision 1.2 1996/08/13 15:07:42 jbk
// changes for better string manipulation and fixes for the units field
//
@@ -84,7 +87,16 @@ static void aitConvertFixedStringString(void* d,const void* s,aitIndex c)
aitString* in = (aitString*)s;
aitFixedString* out = (aitFixedString*)d;
for(i=0;i<c;i++) strcpy(out[i].fixed_string,in[i].string());
//
// joh - changed this from strcpy() to stncpy() in order to:
// 1) shut up purify
// 2) guarantee that all fixed strings will be terminated
// 3) guarantee that we will not overflow a fixed string
//
for(i=0;i<c;i++){
strncpy(out[i].fixed_string,in[i].string(),AIT_FIXED_STRING_SIZE);
out[i].fixed_string[AIT_FIXED_STRING_SIZE-1u] = '\0';
}
}
static void aitConvertToNetStringFixedString(void* d,const void* s,aitIndex c)
+9
View File
@@ -5,6 +5,9 @@
* $Id$
*
* $Log$
* Revision 1.3 1996/08/13 15:07:44 jbk
* changes for better string manipulation and fixes for the units field
*
* Revision 1.2 1996/06/27 14:33:13 jbk
* changes data type to string conversions to use installString(), not copy()
*
@@ -285,6 +288,12 @@ void MakeFStringFuncFrom(int i,int j,int k)
else if(j==aitEnumUint8)
pr(dfd,"\t\titmp=(aitUint32)in[i];\n");
/*
* shut up purify
* (sprintf is so slow that is unliekly to be significant overhead)
*/
pr(dfd,"\t\tmemset(out[i].fixed_string,\'\\0\',sizeof(aitFixedString));\n");
if(j==aitEnumInt8)
pr(dfd,"\t\tsprintf(out[i].fixed_string,aitStringType[aitEnumInt32],itmp);\n");
else if(j==aitEnumUint8)
+12 -1
View File
@@ -8,6 +8,9 @@
* $Id$
*
* $Log$
* Revision 1.8 1996/10/17 12:41:06 jbk
* network byte order stuff / added strDup function to Helpers
*
* Revision 1.7 1996/08/22 21:05:39 jbk
* More fixes to make strings and fixed string work better.
*
@@ -42,6 +45,12 @@
#include <assert.h>
#endif
<<<<<<< aitHelpers.h
#define NSecPerSec 1000000000u
#define NSecPerUSec 1000u
#define SecPerMin 60u
=======
inline char* strDup(const char* x)
{
char* y = new char[strlen(x)+1];
@@ -53,6 +62,7 @@ const unsigned NSecPerSec = 1000000000u;
const unsigned NSecPerUSec = 1000u;
const unsigned SecPerMin = 60u;
>>>>>>> 1.8
class aitTimeStamp {
friend aitTimeStamp operator+ (const aitTimeStamp &lhs, const aitTimeStamp &rhs);
friend aitTimeStamp operator- (const aitTimeStamp &lhs, const aitTimeStamp &rhs);
@@ -263,7 +273,8 @@ inline int aitString::set(const char* p,aitUint32 l)
str=new char[len+1];
if(str)
{
strcpy(str, p);
strncpy(str, p, len);
str[len] = '\0';
type=aitStrMalloc;
}
else
+77 -16
View File
@@ -4,6 +4,10 @@
// $Id$
//
// $Log$
// Revision 1.14 1996/09/10 15:06:28 jbk
// Adjusted dbMapper.cc so gdd to string function work correctly
// Added checks in gdd.h so that get(pointer) functions work with scalars
//
// Revision 1.13 1996/08/23 20:29:35 jbk
// completed fixes for the aitString and fixed string management
//
@@ -449,6 +453,7 @@ static int mapStsGddToChar(void* v, gdd* dd)
dbr_sts_char* dbv = (dbr_sts_char*)v;
int sz=mapGddToChar(&dbv->value,dd);
dd->getStatSevr(dbv->status,dbv->severity);
dbv->RISC_pad = '\0'; // shut up purify
return sz;
}
@@ -481,6 +486,7 @@ static int mapStsGddToDouble(void* v, gdd* dd)
dbr_sts_double* dbv = (dbr_sts_double*)v;
int sz=mapGddToDouble(&dbv->value,dd);
dd->getStatSevr(dbv->status,dbv->severity);
dbv->RISC_pad = 0; // shut up purify
return sz;
}
@@ -546,6 +552,7 @@ static int mapTimeGddToShort(void* v, gdd* dd)
int sz=mapGddToShort(&dbv->value,dd);
dd->getStatSevr(dbv->status,dbv->severity);
dd->getTimeStamp((aitTimeStamp*)&dbv->stamp);
dbv->RISC_pad = 0; // shut up purify
return sz;
}
@@ -582,6 +589,7 @@ static int mapTimeGddToEnum(void* v, gdd* dd)
int sz=mapGddToEnum(&dbv->value,dd);
dd->getStatSevr(dbv->status,dbv->severity);
dd->getTimeStamp((aitTimeStamp*)&dbv->stamp);
dbv->RISC_pad = 0; // shut up purify
return sz;
}
@@ -600,6 +608,8 @@ static int mapTimeGddToChar(void* v, gdd* dd)
int sz=mapGddToChar(&dbv->value,dd);
dd->getStatSevr(dbv->status,dbv->severity);
dd->getTimeStamp((aitTimeStamp*)&dbv->stamp);
dbv->RISC_pad0 = 0; // shut up purify
dbv->RISC_pad1 = '\0'; // shut up purify
return sz;
}
@@ -636,6 +646,7 @@ static int mapTimeGddToDouble(void* v, gdd* dd)
int sz=mapGddToDouble(&dbv->value,dd);
dd->getStatSevr(dbv->status,dbv->severity);
dd->getTimeStamp((aitTimeStamp*)&dbv->stamp);
dbv->RISC_pad = 0; // shut up purify
return sz;
}
@@ -718,7 +729,10 @@ static int mapGraphicGddToShort(void* v, gdd* dd)
aitString* str;
dd[gddAppTypeIndex_dbr_gr_short_units].getRef(str);
if(str->string()) strcpy(db->units,str->string());
if(str->string()) {
strncpy(db->units,str->string(), sizeof(db->units));
db->units[sizeof(db->units)-1u] = '\0';
}
db->lower_disp_limit=dd[gddAppTypeIndex_dbr_gr_short_graphicLow];
db->upper_disp_limit=dd[gddAppTypeIndex_dbr_gr_short_graphicHigh];
@@ -746,7 +760,10 @@ static int mapControlGddToShort(void* v, gdd* dd)
aitString* str;
dd[gddAppTypeIndex_dbr_ctrl_short_units].getRef(str);
if(str->string()) strcpy(db->units,str->string());
if(str->string()) {
strncpy(db->units,str->string(), sizeof(db->units));
db->units[sizeof(db->units)-1u] = '\0';
}
db->lower_disp_limit=dd[gddAppTypeIndex_dbr_ctrl_short_graphicLow];
db->upper_disp_limit=dd[gddAppTypeIndex_dbr_ctrl_short_graphicHigh];
@@ -845,7 +862,10 @@ static int mapGraphicGddToFloat(void* v, gdd* dd)
aitString* str;
dd[gddAppTypeIndex_dbr_gr_float_units].getRef(str);
if(str->string()) strcpy(db->units,str->string());
if(str->string()) {
strncpy(db->units,str->string(), sizeof(db->units));
db->units[sizeof(db->units)-1u] = '\0';
}
db->precision=dd[gddAppTypeIndex_dbr_gr_float_precision];
db->lower_disp_limit=dd[gddAppTypeIndex_dbr_gr_float_graphicLow];
@@ -854,6 +874,7 @@ static int mapGraphicGddToFloat(void* v, gdd* dd)
db->upper_alarm_limit=dd[gddAppTypeIndex_dbr_gr_float_alarmHigh];
db->lower_warning_limit=dd[gddAppTypeIndex_dbr_gr_float_alarmLowWarning];
db->upper_warning_limit=dd[gddAppTypeIndex_dbr_gr_float_alarmHighWarning];
db->RISC_pad0 = 0; // shut up purify
vdd.getStatSevr(db->status,db->severity);
@@ -874,7 +895,10 @@ static int mapControlGddToFloat(void* v, gdd* dd)
aitString* str;
dd[gddAppTypeIndex_dbr_ctrl_float_units].getRef(str);
if(str->string()) strcpy(db->units,str->string());
if(str->string()) {
strncpy(db->units,str->string(), sizeof(db->units));
db->units[sizeof(db->units)-1u] = '\0';
}
db->precision=dd[gddAppTypeIndex_dbr_ctrl_float_precision];
db->lower_disp_limit=dd[gddAppTypeIndex_dbr_ctrl_float_graphicLow];
@@ -885,6 +909,7 @@ static int mapControlGddToFloat(void* v, gdd* dd)
db->upper_alarm_limit=dd[gddAppTypeIndex_dbr_ctrl_float_alarmHigh];
db->lower_warning_limit=dd[gddAppTypeIndex_dbr_ctrl_float_alarmLowWarning];
db->upper_warning_limit=dd[gddAppTypeIndex_dbr_ctrl_float_alarmHighWarning];
db->RISC_pad = 0; // shut up purify
vdd.getStatSevr(db->status,db->severity);
@@ -926,7 +951,11 @@ static gdd* mapGraphicEnumToGdd(void* v, aitIndex /*count*/)
sz=db->no_str;
}
for(i=0;i<sz;i++) strcpy(str[i].fixed_string,&(db->strs[i][0]));
for (i=0;i<sz;i++) {
strncpy(str[i].fixed_string,&(db->strs[i][0]),
sizeof(aitFixedString));
str[i].fixed_string[sizeof(aitFixedString)-1u] = '\0';
}
menu.setBound(0,0,sz);
// should always be a scaler
@@ -964,7 +993,11 @@ static gdd* mapControlEnumToGdd(void* v, aitIndex /*count*/)
sz=db->no_str;
}
for(i=0;i<sz;i++) strcpy(str[i].fixed_string,&(db->strs[i][0]));
for (i=0;i<sz;i++) {
strncpy(str[i].fixed_string,&(db->strs[i][0]),
sizeof(aitFixedString));
str[i].fixed_string[sizeof(aitFixedString)-1u] = '\0';
}
menu.setBound(0,0,sz);
// should always be a scaler
@@ -989,8 +1022,11 @@ static int mapGraphicGddToEnum(void* v, gdd* dd)
if(str && str!=f)
{
for(i=0;i<db->no_str;i++)
strcpy(&(db->strs[i][0]),str[i].fixed_string);
for(i=0;i<db->no_str;i++) {
strncpy(&(db->strs[i][0]),str[i].fixed_string,
sizeof(aitFixedString));
db->strs[i][sizeof(aitFixedString)-1u] = '\0';
}
}
return 1;
}
@@ -1010,8 +1046,11 @@ static int mapControlGddToEnum(void* v, gdd* dd)
if(str && str!=f)
{
for(i=0;i<db->no_str;i++)
strcpy(&(db->strs[i][0]),str[i].fixed_string);
for(i=0;i<db->no_str;i++) {
strncpy(&(db->strs[i][0]),str[i].fixed_string,
sizeof(aitFixedString));
db->strs[i][sizeof(aitFixedString)-1u] = '\0';
}
}
return 1;
}
@@ -1091,7 +1130,10 @@ static int mapGraphicGddToChar(void* v, gdd* dd)
aitString* str;
dd[gddAppTypeIndex_dbr_gr_char_units].getRef(str);
if(str->string()) strcpy(db->units,str->string());
if(str->string()) {
strncpy(db->units,str->string(), sizeof(db->units));
db->units[sizeof(db->units)-1u] = '\0';
}
db->lower_disp_limit=dd[gddAppTypeIndex_dbr_gr_char_graphicLow];
db->upper_disp_limit=dd[gddAppTypeIndex_dbr_gr_char_graphicHigh];
@@ -1099,6 +1141,7 @@ static int mapGraphicGddToChar(void* v, gdd* dd)
db->upper_alarm_limit=dd[gddAppTypeIndex_dbr_gr_char_alarmHigh];
db->lower_warning_limit=dd[gddAppTypeIndex_dbr_gr_char_alarmLowWarning];
db->upper_warning_limit=dd[gddAppTypeIndex_dbr_gr_char_alarmHighWarning];
db->RISC_pad = 0;
vdd.getStatSevr(db->status,db->severity);
@@ -1119,7 +1162,10 @@ static int mapControlGddToChar(void* v, gdd* dd)
aitString* str;
dd[gddAppTypeIndex_dbr_ctrl_char_units].getRef(str);
if(str->string()) strcpy(db->units,str->string());
if(str->string()) {
strncpy(db->units,str->string(), sizeof(db->units));
db->units[sizeof(db->units)-1u] = '\0';
}
db->lower_disp_limit=dd[gddAppTypeIndex_dbr_ctrl_char_graphicLow];
db->upper_disp_limit=dd[gddAppTypeIndex_dbr_ctrl_char_graphicHigh];
@@ -1129,6 +1175,7 @@ static int mapControlGddToChar(void* v, gdd* dd)
db->upper_alarm_limit=dd[gddAppTypeIndex_dbr_ctrl_char_alarmHigh];
db->lower_warning_limit=dd[gddAppTypeIndex_dbr_ctrl_char_alarmLowWarning];
db->upper_warning_limit=dd[gddAppTypeIndex_dbr_ctrl_char_alarmHighWarning];
db->RISC_pad = '\0'; // shut up purify
vdd.getStatSevr(db->status,db->severity);
@@ -1216,7 +1263,10 @@ static int mapGraphicGddToLong(void* v, gdd* dd)
aitString* str;
dd[gddAppTypeIndex_dbr_gr_long_units].getRef(str);
if(str->string()) strcpy(db->units,str->string());
if(str->string()) {
strncpy(db->units,str->string(), sizeof(db->units));
db->units[sizeof(db->units)-1u] = '\0';
}
db->lower_disp_limit=dd[gddAppTypeIndex_dbr_gr_long_graphicLow];
db->upper_disp_limit=dd[gddAppTypeIndex_dbr_gr_long_graphicHigh];
@@ -1244,7 +1294,10 @@ static int mapControlGddToLong(void* v, gdd* dd)
aitString* str;
dd[gddAppTypeIndex_dbr_ctrl_long_units].getRef(str);
if(str->string()) strcpy(db->units,str->string());
if(str->string()) {
strncpy(db->units,str->string(), sizeof(db->units));
db->units[sizeof(db->units)-1u] = '\0';
}
db->lower_disp_limit=dd[gddAppTypeIndex_dbr_ctrl_long_graphicLow];
db->upper_disp_limit=dd[gddAppTypeIndex_dbr_ctrl_long_graphicHigh];
@@ -1343,7 +1396,10 @@ static int mapGraphicGddToDouble(void* v, gdd* dd)
aitString* str;
dd[gddAppTypeIndex_dbr_gr_double_units].getRef(str);
if(str->string()) strcpy(db->units,str->string());
if(str->string()) {
strncpy(db->units,str->string(), sizeof(db->units));
db->units[sizeof(db->units)-1u] = '\0';
}
db->precision=dd[gddAppTypeIndex_dbr_gr_double_precision];
db->lower_disp_limit=dd[gddAppTypeIndex_dbr_gr_double_graphicLow];
@@ -1352,6 +1408,7 @@ static int mapGraphicGddToDouble(void* v, gdd* dd)
db->upper_alarm_limit=dd[gddAppTypeIndex_dbr_gr_double_alarmHigh];
db->lower_warning_limit=dd[gddAppTypeIndex_dbr_gr_double_alarmLowWarning];
db->upper_warning_limit=dd[gddAppTypeIndex_dbr_gr_double_alarmHighWarning];
db->RISC_pad0 = 0; // shut up purify
vdd.getStatSevr(db->status,db->severity);
@@ -1372,7 +1429,10 @@ static int mapControlGddToDouble(void* v, gdd* dd)
aitString* str;
dd[gddAppTypeIndex_dbr_ctrl_double_units].getRef(str);
if(str->string()) strcpy(db->units,str->string());
if(str->string()) {
strncpy(db->units,str->string(), sizeof(db->units));
db->units[sizeof(db->units)-1u] = '\0';
}
db->precision=dd[gddAppTypeIndex_dbr_ctrl_double_precision];
db->lower_disp_limit=dd[gddAppTypeIndex_dbr_ctrl_double_graphicLow];
@@ -1383,6 +1443,7 @@ static int mapControlGddToDouble(void* v, gdd* dd)
db->upper_alarm_limit=dd[gddAppTypeIndex_dbr_ctrl_double_alarmHigh];
db->lower_warning_limit=dd[gddAppTypeIndex_dbr_ctrl_double_alarmLowWarning];
db->upper_warning_limit=dd[gddAppTypeIndex_dbr_ctrl_double_alarmHighWarning];
db->RISC_pad0 = '\0'; // shut up purify
vdd.getStatSevr(db->status,db->severity);
+18 -6
View File
@@ -4,6 +4,9 @@
// $Id$
//
// $Log$
// Revision 1.12 1996/10/29 15:39:58 jbk
// Much new doc added. Fixed bug in gdd.cc.
//
// Revision 1.11 1996/08/27 13:05:05 jbk
// final repairs to string functions, put() functions, and error code printing
//
@@ -1082,10 +1085,16 @@ void gdd::get(aitString& d)
}
void gdd::get(aitFixedString& d)
{
if(primitiveType()==aitEnumFixedString)
strcpy(d.fixed_string,data.FString->fixed_string);
else if(primitiveType()==aitEnumInt8 && dim==1)
strcpy(d.fixed_string,(char*)dataPointer());
if(primitiveType()==aitEnumFixedString){
strncpy(d.fixed_string,data.FString->fixed_string,
sizeof(d));
d.fixed_string[sizeof(d)-1u] = '\0';
}
else if(primitiveType()==aitEnumInt8 && dim==1) {
strncpy(d.fixed_string,(char*)dataPointer(),
sizeof(d));
d.fixed_string[sizeof(d)-1u] = '\0';
}
else
get(aitEnumFixedString,&d);
}
@@ -1111,8 +1120,11 @@ void gdd::getConvert(aitString& d)
void gdd::getConvert(aitFixedString& d)
{
if(primitiveType()==aitEnumInt8 && dim==1)
strcpy(d.fixed_string,(char*)dataPointer());
if(primitiveType()==aitEnumInt8 && dim==1){
strncpy(d.fixed_string,(char*)dataPointer(),
sizeof(d));
d.fixed_string[sizeof(d)-1u] = '\0';
}
else
get(aitEnumFixedString,d.fixed_string);
}
+8 -2
View File
@@ -8,6 +8,9 @@
* $Id$
*
* $Log$
* Revision 1.16 1996/10/17 12:39:14 jbk
* removed strdup definition, fixed up the local/network byte order functions
*
* Revision 1.15 1996/09/10 15:06:29 jbk
* Adjusted dbMapper.cc so gdd to string function work correctly
* Added checks in gdd.h so that get(pointer) functions work with scalars
@@ -909,8 +912,11 @@ inline gddStatus gdd::put(const aitInt8* const d)
aitString* p = (aitString*)dataAddress();
p->installString((char*)d);
}
else if(primitiveType()==aitEnumFixedString && dim==0)
strcpy(data.FString->fixed_string,(char*)d);
else if(primitiveType()==aitEnumFixedString && dim==0) {
strncpy(data.FString->fixed_string,(char*)d,
sizeof(aitFixedString));
data.FString->fixed_string[sizeof(aitFixedString)-1u]='\0';
}
else
rc=genCopy(aitEnumInt8,d);