Skip to content

Commit

Permalink
Clean up Clang 15 sprintf() warnings in libcom and ca
Browse files Browse the repository at this point in the history
  • Loading branch information
anjohnson committed Dec 13, 2023
1 parent 56dbc94 commit 5ecf7d1
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion modules/ca/src/client/acctst.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
4 changes: 2 additions & 2 deletions modules/ca/src/client/cac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion modules/libcom/src/osi/epicsTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion modules/libcom/test/epicsEventTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/libcom/test/epicsMessageQueueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion modules/libcom/test/epicsMutexTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion modules/libcom/test/epicsThreadTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5ecf7d1

Please sign in to comment.