Skip to content

Commit e2c0f46

Browse files
authored
Merge pull request #133 from bigbrett/static-analysis-basic-take2
CI static analysis + fixes
2 parents 6a05071 + 0f3d308 commit e2c0f46

File tree

9 files changed

+466
-297
lines changed

9 files changed

+466
-297
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Static Analysis
2+
3+
on:
4+
pull_request:
5+
branches: [ main, master ]
6+
push:
7+
branches: [ main, master ]
8+
9+
jobs:
10+
cppcheck:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Install cppcheck
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install -y cppcheck
21+
22+
- name: Run cppcheck
23+
id: cppcheck
24+
continue-on-error: true
25+
run: |
26+
chmod +x tools/static-analysis/run_cppcheck.sh
27+
tools/static-analysis/run_cppcheck.sh
28+
29+
- name: Display errors and warnings
30+
if: always()
31+
run: |
32+
if [ -f tools/static-analysis/reports/cppcheck_summary.txt ]; then
33+
ERROR_COUNT=$(grep -c "error:" tools/static-analysis/reports/cppcheck_summary.txt 2>/dev/null) || ERROR_COUNT=0
34+
WARNING_COUNT=$(grep -c "warning:" tools/static-analysis/reports/cppcheck_summary.txt 2>/dev/null) || WARNING_COUNT=0
35+
STYLE_COUNT=$(grep -c "style:" tools/static-analysis/reports/cppcheck_summary.txt 2>/dev/null) || STYLE_COUNT=0
36+
37+
echo "## Static Analysis Summary"
38+
echo "- Errors: $ERROR_COUNT"
39+
echo "- Warnings: $WARNING_COUNT"
40+
echo "- Style issues: $STYLE_COUNT (informational only)"
41+
42+
if [ "$ERROR_COUNT" -gt 0 ] || [ "$WARNING_COUNT" -gt 0 ]; then
43+
echo ""
44+
echo "### Issues that must be fixed:"
45+
echo ""
46+
# Show only errors and warnings, not style issues
47+
grep -E "(error|warning):" tools/static-analysis/reports/cppcheck_summary.txt || true
48+
fi
49+
else
50+
echo "⚠️ No cppcheck summary file found"
51+
fi
52+
53+
- name: Fail if issues found
54+
if: steps.cppcheck.outcome == 'failure'
55+
run: |
56+
echo "❌ Static analysis failed - errors or warnings were found"
57+
exit 1

.gitignore

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
.DS_Store
2-
Build/
3-
*.o
4-
*.a
5-
*.la
6-
**/.gdb_history
7-
tools/testcertgen/ca/
8-
tools/testcertgen/*.der
9-
*.code-workspace
10-
.vscode
11-
1+
.DS_Store
2+
Build/
3+
*.o
4+
*.a
5+
*.la
6+
**/.gdb_history
7+
tools/testcertgen/ca/
8+
tools/testcertgen/*.der
9+
*.code-workspace
10+
.vscode
11+
12+
# Static analysis reports
13+
tools/static-analysis/reports/
14+
*.xml
15+
*.html
16+

src/wh_client.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ int wh_Client_Init(whClientContext* c, const whClientConfig* config)
9797
}
9898

9999
#ifdef WOLFHSM_CFG_DMA
100-
rc = wc_CryptoCb_RegisterDevice(WH_DEV_ID_DMA,
101-
wh_Client_CryptoCbDma, c);
102-
if (rc != 0) {
103-
rc = WH_ERROR_ABORTED;
100+
if (rc == 0) {
101+
rc = wc_CryptoCb_RegisterDevice(WH_DEV_ID_DMA,
102+
wh_Client_CryptoCbDma, c);
103+
if (rc != 0) {
104+
rc = WH_ERROR_ABORTED;
105+
}
104106
}
105107
#endif /* WOLFHSM_CFG_DMA */
106108
}
@@ -1498,4 +1500,4 @@ int wh_Client_KeyExportDma(whClientContext* c, uint16_t keyId,
14981500

14991501
#endif /* WOLFHSM_CFG_DMA */
15001502

1501-
#endif /* WOLFHSM_CFG_ENABLE_CLIENT */
1503+
#endif /* WOLFHSM_CFG_ENABLE_CLIENT */

src/wh_client_she.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,9 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader,
120120
{
121121
int ret;
122122
uint32_t bootloaderSent = 0;
123-
uint32_t justSent = 0;
124123
uint16_t group;
125124
uint16_t action;
126125
uint16_t dataSz;
127-
uint8_t* in;
128126
uint8_t* respBuf;
129127

130128
whMessageShe_SecureBootInitRequest* initReq = NULL;
@@ -141,9 +139,6 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader,
141139
(whMessageShe_SecureBootInitRequest*)wh_CommClient_GetDataPtr(c->comm);
142140
respBuf = (uint8_t*)wh_CommClient_GetDataPtr(c->comm);
143141

144-
/* in is after the size argument */
145-
in = (uint8_t*)(initReq + 1);
146-
147142
/* send init sub command */
148143
initReq->sz = bootloaderLen;
149144
ret =
@@ -159,6 +154,9 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader,
159154

160155
/* send update sub command until we've sent the entire bootloader */
161156
while (ret == 0 && bootloaderSent < bootloaderLen) {
157+
uint8_t* in;
158+
uint32_t justSent;
159+
162160
if (initResp->rc != WH_SHE_ERC_NO_ERROR) {
163161
return initResp->rc;
164162
}

src/wh_nvm_flash.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,12 @@ static int nfPartition_ProgramCount(whNvmFlashContext* context,
442442

443443
static int nfPartition_ProgramInit(whNvmFlashContext* context, int partition)
444444
{
445+
int ret = 0;
446+
447+
if ((context == NULL) || (context->cb == NULL)) {
448+
return WH_ERROR_BADARGS;
449+
}
450+
445451
/* Valid initial state values for a partition */
446452
nfMemState init_state =
447453
{
@@ -450,11 +456,6 @@ static int nfPartition_ProgramInit(whNvmFlashContext* context, int partition)
450456
.start = NF_PARTITION_DATA_OFFSET,
451457
.count = context->partition_units,
452458
};
453-
int ret = 0;
454-
455-
if ((context == NULL) || (context->cb == NULL)) {
456-
return WH_ERROR_BADARGS;
457-
}
458459

459460
/* Blankcheck/Erase partition */
460461
ret = nfPartition_BlankCheck(context, partition);
@@ -735,12 +736,11 @@ static int nfObject_Copy(whNvmFlashContext* context, int object_index,
735736
}
736737
ret = nfObject_ProgramFinish(context, partition, dest_object, data_len);
737738
if (ret != 0) return ret;
739+
738740
dest_object++;
741+
*inout_next_object = dest_object;
742+
*inout_next_data = dest_data;
739743

740-
if (ret == 0) {
741-
*inout_next_object = dest_object;
742-
*inout_next_data = dest_data;
743-
}
744744
return ret;
745745
}
746746

0 commit comments

Comments
 (0)