diff --git a/src/turboPmacController.cpp b/src/turboPmacController.cpp index 0cf65b7..068e152 100644 --- a/src/turboPmacController.cpp +++ b/src/turboPmacController.cpp @@ -399,11 +399,23 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command, command, getMsgPrintControl().getSuffix()); } + /* + The literal part of the message below is 113 bytes long. Cap the two + embedded strings (constexpr precision) so that the message always fits + into drvMessageText (MAXBUF_ bytes), otherwise the + -Wformat-truncation check would be triggered. + */ + constexpr size_t msgLiteralLen = + sizeof("Received unexpected response '' (carriage returns are " + "replaced with spaces) for command . Please call the " + "support") - + 1; + constexpr size_t msgArgLen = (MAXBUF_ - msgLiteralLen - 1) / 2; snprintf(drvMessageText, sizeof(drvMessageText), - "Received unexpected response '%s' (carriage returns " - "are replaced with spaces) for command %s. " - "Please call the support", - modResponse, command); + "Received unexpected response '%.*s' (carriage returns " + "are replaced with spaces) for command %.*s. Please call " + "the support", + (int)msgArgLen, modResponse, (int)msgArgLen, command); status = asynError; } else { getMsgPrintControl().resetCount(numResponsesKey, pasynUser());