GCC Code Coverage Report


Directory: ./
File: sscanf_scan.cpp
Date: 2026-09-03 22:13:07
Exec Total Coverage
Lines: 0 19 0.0%
Functions: 0 2 0.0%
Branches: 0 9 0.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title format.cpp
3 // \author mstarch
4 // \brief cpp file for c-string format function as a implementation using snprintf
5 // ======================================================================
6 #include <Fw/Types/StringUtils.hpp>
7 #include <Fw/Types/scan.hpp>
8 #include <cstdio>
9 #include <limits>
10
11 Fw::ScanStatus Fw::stringScan(FwSizeType& count,
12 const char* source,
13 FwSizeType maximumSize,
14 const char* formatString,
15 ...) {
16 va_list args;
17 va_start(args, formatString);
18 Fw::ScanStatus status = Fw::stringScan(count, source, maximumSize, formatString, args);
19 va_end(args);
20 return status;
21 }
22
23 Fw::ScanStatus Fw::stringScan(FwSizeType& count,
24 const char* source,
25 FwSizeType maximumSize,
26 const char* formatString,
27 va_list args) {
28 Fw::ScanStatus scanStatus = Fw::ScanStatus::SUCCESS;
29 count = 0;
30 // Check format string
31 if (formatString == nullptr) {
32 scanStatus = Fw::ScanStatus::INVALID_FORMAT_STRING;
33 }
34 // Must allow the compiler to choose the correct type for comparison
35 else if (maximumSize > std::numeric_limits<size_t>::max()) {
36 scanStatus = Fw::ScanStatus::SIZE_OVERFLOW;
37 }
38 // Check for null-termination of the source string bounded by maximumSize
39 else if (StringUtils::string_length(source, maximumSize) >= maximumSize) {
40 scanStatus = Fw::ScanStatus::UNTERMINATED_SOURCE_STRING;
41 } else {
42 const int scannedFields = vsscanf(source, formatString, args);
43 if (scannedFields < 0) {
44 scanStatus = Fw::ScanStatus::OTHER_ERROR;
45 } else {
46 count = static_cast<FwSizeType>(scannedFields);
47 }
48 }
49 return scanStatus;
50 }
51