Clean up Clang 15 sprintf() warnings in libcom and ca

This commit is contained in:
Andrew Johnson
2023-12-12 13:53:33 -06:00
parent 56dbc949ff
commit 5ecf7d18a8
7 changed files with 10 additions and 9 deletions

View File

@@ -2575,7 +2575,8 @@ void monitorUpdateTest ( chid chan, unsigned interestLevel )
SEVCHK ( ca_get ( DBR_FLOAT, chan, &temp ), NULL );
SEVCHK ( ca_pend_io ( timeoutToPendIO ), NULL );
/* printf ( "flow control bypassed %u events\n", flowCtrlCount ); */
if (0)
printf ( "flow control bypassed %u events\n", flowCtrlCount );
showProgressEnd ( interestLevel );
}

View File

@@ -1008,7 +1008,7 @@ bool cac::defaultExcep (
char buf[512];
char hostName[64];
iiu.getHostName ( guard, hostName, sizeof ( hostName ) );
sprintf ( buf, "host=%s ctx=%.400s", hostName, pCtx );
snprintf( buf, sizeof(buf), "host=%s ctx=%.400s", hostName, pCtx );
this->notify.exception ( guard, status, buf, 0, 0u );
return true;
}
@@ -1312,7 +1312,7 @@ void cac::pvMultiplyDefinedNotify ( msgForMultiplyDefinedPV & mfmdpv,
const char * pChannelName, const char * pAcc, const char * pRej )
{
char buf[256];
sprintf ( buf, "Channel: \"%.64s\", Connecting to: %.64s, Ignored: %.64s",
snprintf( buf, sizeof(buf), "Channel: \"%.64s\", Connecting to: %.64s, Ignored: %.64s",
pChannelName, pAcc, pRej );
{
callbackManager mgr ( this->notify, this->cbMutex );

View File

@@ -238,7 +238,7 @@ size_t epicsStdCall epicsTimeToStrftime (char *pBuff, size_t bufLength, const ch
// convert nanosecs to integer of correct range
frac /= div[fracWid];
char fracFormat[32];
sprintf ( fracFormat, "%%0%lulu", fracWid );
snprintf ( fracFormat, sizeof ( fracFormat ), "%%0%lulu", fracWid );
int status = epicsSnprintf ( pBufCur, bufLenLeft, fracFormat, frac );
if ( status > 0 ) {
unsigned long nChar = static_cast < unsigned long > ( status );

View File

@@ -244,7 +244,7 @@ MAIN(epicsEventTest)
name = (char **)calloc(nthreads, sizeof(char *));
for(int i = 0; i < nthreads; i++) {
name[i] = (char *)calloc(16, sizeof(char));
sprintf(name[i],"producer %d",i);
snprintf(name[i], 16, "producer %d",i);
id[i] = epicsThreadCreate(name[i], 40, stackSize, producer, pinfo);
epicsThreadSleep(0.1);
}

View File

@@ -232,7 +232,7 @@ sender(void *arg)
int i = 0;
while (!sendExit) {
len = sprintf(cbuf, "%s -- %d.", epicsThreadGetNameSelf(), ++i);
len = snprintf(cbuf, sizeof(cbuf), "%s -- %d.", epicsThreadGetNameSelf(), ++i);
while (q->trySend((void *)cbuf, len) < 0)
epicsThreadSleep(0.005 * (randBelow(5)));
epicsThreadSleep(0.005 * (randBelow(20)));
@@ -421,7 +421,7 @@ extern "C" void messageQueueTest(void *parm)
epicsThreadPriorityHigh,
epicsThreadPriorityHigh
};
sprintf(name, "Sender %d", i+1);
snprintf(name, sizeof(name), "Sender %d", i+1);
opts.priority = pri[i];
senderId[i] = epicsThreadCreateOpt(name, sender, &q1, &opts);
if (!senderId[i])

View File

@@ -266,7 +266,7 @@ MAIN(epicsMutexTest)
stackSize = epicsThreadGetStackSize(epicsThreadStackSmall);
for(i=0; i<nthreads; i++) {
name[i] = (char *)calloc(10,sizeof(char));
sprintf(name[i],"task%d",i);
snprintf(name[i], 10, "task%d",i);
pinfo[i] = (info *)calloc(1,sizeof(info));
pinfo[i]->threadnum = i;
pinfo[i]->mutex = mutex;

View File

@@ -73,7 +73,7 @@ void testMyThread()
int startPriority = 0;
for (int i = 0; i < ntasks; i++) {
char name[10];
sprintf(name, "t%d", i);
snprintf(name, sizeof(name), "t%d", i);
myThreads[i] = new myThread(i, name);
if (i == 0)
startPriority = myThreads[i]->thread.getPriority();