Skip to content

Commit 04d2c04

Browse files
fix: Initialize file pointer to NULL before allocation
Co-Authored-By: [email protected] <[email protected]>
1 parent 918435a commit 04d2c04

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

.github/workflows/fatfs-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
echo "typedef struct { FIL fil; FILE* stdio_file; } WFILE;" >> ${{ github.workspace }}/build-dir/include/wolfssh/myFilesystem.h
7070
echo "#define WFD WFILE*" >> ${{ github.workspace }}/build-dir/include/wolfssh/myFilesystem.h
7171
echo "#define WBADFILE ((WFD)NULL)" >> ${{ github.workspace }}/build-dir/include/wolfssh/myFilesystem.h
72-
echo "static inline int ff_fopen(WFD* f, const char* filename, BYTE m) { if(!f) return -1; WFD tmp = malloc(sizeof(WFILE)); if(!tmp) return -1; memset(tmp, 0, sizeof(WFILE)); tmp->stdio_file = tmpfile(); if(!tmp->stdio_file) { free(tmp); return -1; } int ret = f_open(&tmp->fil, filename, m); if(ret != 0) { fclose(tmp->stdio_file); free(tmp); return ret; } *f = tmp; return 0; }" >> ${{ github.workspace }}/build-dir/include/wolfssh/myFilesystem.h
72+
echo "static inline int ff_fopen(WFD* f, const char* filename, BYTE m) { if(!f) return -1; *f = NULL; WFD tmp = malloc(sizeof(WFILE)); if(!tmp) return -1; memset(tmp, 0, sizeof(WFILE)); tmp->stdio_file = tmpfile(); if(!tmp->stdio_file) { free(tmp); return -1; } int ret = f_open(&tmp->fil, filename, m); if(ret != 0) { fclose(tmp->stdio_file); free(tmp); return ret; } *f = tmp; return 0; }" >> ${{ github.workspace }}/build-dir/include/wolfssh/myFilesystem.h
7373
echo "#define ff_fprintf(f, ...) do { FILE* __fp = ff_get_stdio(f); if(__fp) fprintf(__fp, __VA_ARGS__); } while(0)" >> ${{ github.workspace }}/build-dir/include/wolfssh/myFilesystem.h
7474
echo "static inline int ff_fclose(WFD f) { if(!f) return -1; if(f->stdio_file) fclose(f->stdio_file); int ret = f_close(&f->fil); free(f); return ret; }" >> ${{ github.workspace }}/build-dir/include/wolfssh/myFilesystem.h
7575
echo "static inline int ff_fread(void* ptr, size_t size, size_t nmemb, WFD f) { if(!f) return -1; UINT br; int ret = f_read(&f->fil, ptr, size * nmemb, &br); return ret ? -1 : br; }" >> ${{ github.workspace }}/build-dir/include/wolfssh/myFilesystem.h

0 commit comments

Comments
 (0)