Skip to content

Commit 132a0a5

Browse files
committed
Clean up a couple issues where building the code with a C++ reported build errors.
1. Typecasting the return from malloc. 2. strncpy() checking.
1 parent 4b021fc commit 132a0a5

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

examples/echoserver/echoserver.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,20 +588,20 @@ static int shell_worker(thread_ctx_t* threadCtx)
588588
memset((void *)&buf_rx, 0, sizeof(buf_rx));
589589
memset((void *)&buf_tx, 0, sizeof(buf_tx));
590590

591-
buf_rx.buf = malloc(SE_BUF_SIZE);
591+
buf_rx.buf = (char*)malloc(SE_BUF_SIZE);
592592
if (buf_rx.buf == NULL) {
593593
return WS_FATAL_ERROR;
594594
}
595595

596-
buf_tx.buf = malloc(SE_BUF_SIZE);
596+
buf_tx.buf = (char*)malloc(SE_BUF_SIZE);
597597
if (buf_tx.buf == NULL) {
598598
free(buf_rx.buf);
599599
return WS_FATAL_ERROR;
600600
}
601601

602602
#ifdef WOLFSSH_AGENT
603603
memset((void *)&agent_buf, 0, sizeof(agent_buf));
604-
agent_buf.buf = malloc(SE_BUF_SIZE);
604+
agent_buf.buf = (char*)malloc(SE_BUF_SIZE);
605605
if (agent_buf.buf == NULL) {
606606
free(buf_rx.buf);
607607
free(buf_tx.buf);

src/wolfscp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,8 @@ int ScpPushDir(ScpSendCtx* ctx, const char* path, void* heap)
20582058
}
20592059

20602060
/* append directory name to ctx->dirName */
2061-
WSTRNCPY(ctx->dirName, path, DEFAULT_SCP_FILE_NAME_SZ);
2061+
WSTRNCPY(ctx->dirName, path, DEFAULT_SCP_FILE_NAME_SZ-1);
2062+
ctx->dirName[DEFAULT_SCP_FILE_NAME_SZ-1] = '\0';
20622063

20632064
return WS_SUCCESS;
20642065
}

0 commit comments

Comments
 (0)