-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 2358 evs fmt mk2 #2382
base: main
Are you sure you want to change the base?
Fix 2358 evs fmt mk2 #2382
Conversation
@@ -98,6 +98,8 @@ | |||
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TIME_INVALID_MID = {.MsgId = CFE_SB_MSGID_RESERVED, .CommandCode = 0}; | |||
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TIME_CMD_INVALID_CC = { | |||
.MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_TIME_CMD_MID), .CommandCode = 0x7F}; | |||
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TIME_SET_PRINT_CC = { |
Check notice
Code scanning / CodeQL
Variable scope too large
@@ -240,6 +240,13 @@ | |||
} | |||
break; | |||
|
|||
case CFE_TIME_SET_PRINT_CC: | |||
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetPrintCmd_t))) |
Check warning
Code scanning / CodeQL
Side effect in a Boolean expression
* See description in header file for argument/return detail | ||
* | ||
*-----------------------------------------------------------------*/ | ||
int32 CFE_TIME_SetPrintFormat(CFE_TIME_PrintTimestamp_Enum_t PrintTimestamp, const char *PrintFormat) |
Check notice
Code scanning / CodeQL
Long function without assertion
while (PctF[0] != '\0') { | ||
if (PctF[0] == '%') | ||
{ | ||
switch (PctF[1]) | ||
{ | ||
case 'f': | ||
CFE_TIME_Global.PrintFormatMillis = PctF; | ||
break; | ||
case '\0': | ||
break; | ||
default: | ||
PctF++; /* skip forward two chars */ | ||
} | ||
} | ||
PctF++; | ||
} |
Check warning
Code scanning / CodeQL
Unbounded loop
switch (CFE_TIME_Global.PrintTimestamp) | ||
{ | ||
case CFE_TIME_PrintTimestamp_DateTime: | ||
gmtime_r(&sec, &tm); | ||
|
||
/* | ||
** `PrintFormatMillis` points at the `%f` in PrintFormat, if there is a `%f`. | ||
*/ | ||
if (CFE_TIME_Global.PrintFormatMillis) | ||
{ | ||
/* ...blot out the `%f`, temporarily. */ | ||
CFE_TIME_Global.PrintFormatMillis[0] = '\0'; | ||
} | ||
|
||
TimeSz = strftime(PrintBuffer, CFE_TIME_PRINTED_STRING_SIZE, CFE_TIME_Global.PrintFormat, &tm); | ||
|
||
if (TimeSz == 0) | ||
{ | ||
return CFE_TIME_FORMAT_TOO_LONG; | ||
} | ||
|
||
OutChrs += TimeSz; | ||
|
||
if (CFE_TIME_Global.PrintFormatMillis) | ||
{ | ||
/* unblot */ | ||
CFE_TIME_Global.PrintFormatMillis[0] = '%'; | ||
|
||
if (OutChrs + 6 > CFE_TIME_PRINTED_STRING_SIZE) | ||
{ | ||
return CFE_TIME_FORMAT_TOO_LONG; | ||
} | ||
|
||
OutChrs += snprintf(PrintBuffer + OutChrs, CFE_TIME_PRINTED_STRING_SIZE - OutChrs, "%05d", mic); | ||
|
||
/* it's likely the `%f` is last in the format string, check if there's any remainder...*/ | ||
if (CFE_TIME_Global.PrintFormatMillis[2]) | ||
{ | ||
TimeSz = strftime(PrintBuffer + OutChrs, CFE_TIME_PRINTED_STRING_SIZE, CFE_TIME_Global.PrintFormatMillis + 2, &tm); | ||
|
||
if (TimeSz == 0) | ||
{ | ||
return CFE_TIME_FORMAT_TOO_LONG; | ||
} | ||
|
||
OutChrs += TimeSz; | ||
} | ||
} | ||
PrintBuffer[OutChrs] = '\0'; | ||
break; | ||
|
||
case CFE_TIME_PrintTimestamp_SecsSinceStart: | ||
OutChrs += snprintf(PrintBuffer, CFE_TIME_PRINTED_STRING_SIZE, "%ld.%06d", (long int)sec, mic); | ||
PrintBuffer[OutChrs] = '\0'; | ||
break; | ||
|
||
default: | ||
PrintBuffer[0] = '\0'; | ||
break; | ||
} |
Check notice
Code scanning / CodeQL
Long switch case
*-----------------------------------------------------------------*/ | ||
int32 CFE_TIME_SetPrintFormat(CFE_TIME_PrintTimestamp_Enum_t PrintTimestamp, const char *PrintFormat) | ||
{ | ||
if (PrintTimestamp < 0 || PrintTimestamp > CFE_TIME_PrintTimestamp_None) |
Check warning
Code scanning / CodeQL
Comparison result is always the same
Joe, for your consideration, another pass at the "%f" and strftime code. This simplifies it a bit (but only supports one "%f" in the format string.)