Using sprintf Instead of snprintf

This commit is contained in:
2025-12-09 21:09:25 +01:00
parent ba2f036d88
commit 7c92386082
3 changed files with 33 additions and 31 deletions

View File

@ -42,17 +42,17 @@ void Printer::print(Drive *drive)
t_msgQueueData msgQueueData;
msgQueueData.msg_queue_type = 1;
sprintf(msgQueueData.driveData.caDriveIndex, "%i", 42); // TODO: get from tui
sprintf(msgQueueData.driveData.caDriveState, "shredded");
snprintf(msgQueueData.driveData.caDriveIndex, STR_BUFFER_SIZE, "%i", drive->u16DriveIndex);
snprintf(msgQueueData.driveData.caDriveState, STR_BUFFER_SIZE, "shredded");
strcpy(msgQueueData.driveData.caDriveModelFamily, drive->getModelFamily().c_str());
strcpy(msgQueueData.driveData.caDriveModelName, drive->getModelName().c_str());
sprintf(msgQueueData.driveData.caDriveCapacity, "%li", drive->getCapacity());
snprintf(msgQueueData.driveData.caDriveCapacity, STR_BUFFER_SIZE, "%li", drive->getCapacity());
strcpy(msgQueueData.driveData.caDriveSerialnumber, drive->getSerial().c_str());
sprintf(msgQueueData.driveData.caDriveHours, "%i", drive->getPowerOnHours());
sprintf(msgQueueData.driveData.caDriveCycles, "%i", drive->getPowerCycles());
sprintf(msgQueueData.driveData.caDriveErrors, "%i", drive->getErrorCount());
sprintf(msgQueueData.driveData.caDriveShredTimestamp, "%li", drive->getActionStartTimestamp());
sprintf(msgQueueData.driveData.caDriveShredDuration, "%li", drive->getTaskDuration());
snprintf(msgQueueData.driveData.caDriveHours, STR_BUFFER_SIZE, "%i", drive->getPowerOnHours());
snprintf(msgQueueData.driveData.caDriveCycles, STR_BUFFER_SIZE, "%i", drive->getPowerCycles());
snprintf(msgQueueData.driveData.caDriveErrors, STR_BUFFER_SIZE, "%i", drive->getErrorCount());
snprintf(msgQueueData.driveData.caDriveShredTimestamp, STR_BUFFER_SIZE, "%li", drive->getActionStartTimestamp());
snprintf(msgQueueData.driveData.caDriveShredDuration, STR_BUFFER_SIZE, "%li", drive->getTaskDuration());
switch (drive->connectionType)
{
@ -70,7 +70,7 @@ void Printer::print(Drive *drive)
strcpy(msgQueueData.driveData.caDriveConnectionType, "na");
}
sprintf(msgQueueData.driveData.caDriveReHddVersion, REHDD_VERSION);
snprintf(msgQueueData.driveData.caDriveReHddVersion, STR_BUFFER_SIZE, "%s", REHDD_VERSION);
if (-1 == msgsnd(this->msqid, &msgQueueData, sizeof(t_msgQueueData) - sizeof(long), 0))
{