Skip to content

Commit 12a6d9c

Browse files
committed
refactor: reduced warnings from MSVC
1 parent d3b2fdc commit 12a6d9c

File tree

15 files changed

+146
-199
lines changed

15 files changed

+146
-199
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# run68x 2.0.2 (2024-10-17)
2+
3+
* `DOS _CREATE``DOS _NEWFILE``DOS _OPEN`の処理を書き直した。
4+
* (win32) `DOS _OPEN`でオープン済みファイルを更にオープンできるようにした。
5+
* (generic) `DOS _CREATE``DOS _NEWFILE`でキャラクタデバイスをオープン
6+
できないようにした。
7+
* (generic) `DOS _FILES`でファイルサイズを取得するようにした。
8+
9+
110
# run68x 2.0.1 (2024-06-12)
211

312
* `MOVEM (An)+,An`命令で`An`レジスタの値が正しくない不具合を修正。

src/ansicolor-w32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ int WriteW32(short _type, HANDLE handle, const char *_buf, size_t _len) {
2929
DWORD written, csize;
3030
CONSOLE_CURSOR_INFO cci;
3131
CONSOLE_SCREEN_BUFFER_INFO csbi;
32-
COORD coord;
32+
COORD coord = {0};
3333
const char *ptr;
3434

3535
if (_type == 1) {
@@ -54,8 +54,8 @@ int WriteW32(short _type, HANDLE handle, const char *_buf, size_t _len) {
5454
while (*ptr) {
5555
if (*ptr == '\033') {
5656
unsigned char c;
57-
int i, n = 0, m, v[6], w, h;
58-
for (i = 0; i < 6; i++) v[i] = -1;
57+
int i, n = 0, m = 0, w, h;
58+
int v[6] = { -1, -1, -1, -1, -1, -1 };
5959
ptr++;
6060
retry:
6161
if ((c = *ptr++) == 0) break;

src/debugger.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ static UWord watchcode(int argc, char **argv) {
8989
debuggerError("watchcode:Instruction code expression error.\n");
9090
return 0x4afc;
9191
}
92-
sscanf(&argv[1][1], "%hx", &wcode);
93-
return (UWord)wcode;
92+
return (sscanf(&argv[1][1], "%hx", &wcode) == 1) ? (UWord)wcode : 0;
9493
}
9594

9695
/*
@@ -409,8 +408,7 @@ static void set_breakpoint(int argc, char **argv) {
409408

410409
{
411410
long unsigned int a;
412-
sscanf(&argv[1][1], "%lx", &a);
413-
settings.trapPc = (ULong)a;
411+
settings.trapPc = (sscanf(&argv[1][1], "%lx", &a) == 1) ? (ULong)a : 0;
414412
}
415413
}
416414

@@ -423,7 +421,7 @@ static void display_history(int argc, char **argv) {
423421
} else if (determine_string(argv[1]) != 1) {
424422
debuggerError("history:Argument error.\n");
425423
} else {
426-
sscanf(argv[1], "%d", &n);
424+
n = (sscanf(argv[1], "%d", &n) == 1) ? n : 10;
427425
}
428426
OPBuf_display(n);
429427
}
@@ -448,12 +446,14 @@ static void display_list(int argc, char **argv) {
448446
}
449447
if (2 <= argc) {
450448
if (argc == 2 && determine_string(argv[1]) == 1) {
451-
sscanf(argv[1], "%d", &n);
449+
n = (sscanf(argv[1], "%d", &n) == 1) ? n : 10;
452450
} else if (argc >= 2 && determine_string(argv[1]) == 2) {
453-
sscanf(&argv[1][1], "%x", &addr);
451+
addr = (sscanf(&argv[1][1], "%x", &addr) == 1) ? addr
452+
: (list_addr == 0) ? pc
453+
: list_addr;
454454
}
455455
if (argc == 3 && determine_string(argv[2]) == 1) {
456-
sscanf(argv[2], "%d", &n);
456+
n = (sscanf(argv[2], "%d", &n) == 1) ? n : 10;
457457
}
458458
}
459459
for (i = 0; i < n; i++) {
@@ -495,8 +495,7 @@ static ULong get_stepcount(int argc, char **argv) {
495495
return 0;
496496
} else if (determine_string(argv[1]) == 1) {
497497
long unsigned int a;
498-
sscanf(argv[1], "%lu", &a);
499-
count = (ULong)a;
498+
count = (sscanf(argv[1], "%lu", &a) == 1) ? (ULong)a : 0;
500499
}
501500
return count;
502501
}

src/dos_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Long Seek(UWord fileno, Long offset, UWord mode) {
183183

184184
// 最後のパスデリミタ(\ : /)の次のアドレスを求める
185185
// パスデリミタがなければ文字列先頭を返す
186-
char* get_filename(char* path) {
186+
static char* get_filename(char* path) {
187187
char* filename = path;
188188
char* p = path;
189189
char c;

src/dos_memory.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static ULong tryMalloc(UByte mode, ULong sizeWithHeader, ULong parent,
114114

115115
ULong memoryEnd = ReadULongSuper(OSWORK_MEMORY_END);
116116
ULong memblk = ReadULongSuper(OSWORK_ROOT_PSP);
117-
ULong next;
117+
ULong next = 0;
118118
for (; memblk != 0; memblk = next) {
119119
next = ReadULongSuper(memblk + MEMBLK_NEXT);
120120

@@ -206,8 +206,8 @@ Long Mfree(ULong adr) {
206206

207207
// 指定したプロセスが確保したメモリブロックを全て解放する
208208
static void MfreeAll(ULong psp) {
209-
ULong next, m;
210-
for (m = ReadULongSuper(OSWORK_ROOT_PSP);; m = next) {
209+
ULong next = 0;
210+
for (ULong m = ReadULongSuper(OSWORK_ROOT_PSP);; m = next) {
211211
next = ReadULongSuper(m + MEMBLK_NEXT);
212212

213213
ULong parent = ReadULongSuper(m + MEMBLK_PARENT);
@@ -281,8 +281,8 @@ Long SetblockHuge(ULong adr, ULong size) {
281281
static bool is_valid_memblk(ULong memblk, ULong* nextptr) {
282282
if (nextptr != NULL) *nextptr = 0;
283283

284-
ULong next, m;
285-
for (m = ReadULongSuper(OSWORK_ROOT_PSP);; m = next) {
284+
ULong next = 0;
285+
for (ULong m = ReadULongSuper(OSWORK_ROOT_PSP);; m = next) {
286286
next = ReadULongSuper(m + MEMBLK_NEXT);
287287
if (m == memblk) break;
288288
if (next == 0) return false;

src/doscall.c

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static Long Gets(Long);
5959
static Long Kflush(short);
6060
static Long Ioctrl(short, Long);
6161
static Long Dup(short);
62-
static Long Dup2(short, short);
62+
static Long Dup2(short org, short new);
6363
static Long Dskfre(short, Long);
6464
static Long Close(short);
6565
static Long Fgets(Long, short);
@@ -91,13 +91,13 @@ static Long Exec3(ULong, Long, Long);
9191
static void Exec4(Long);
9292

9393
#ifndef _WIN32
94-
int _dos_getfileattr(char* name, void* ret) {
94+
static int _dos_getfileattr(char* name, void* ret) {
9595
printf("_dos_getfileattr(\"%s\")\n", name);
9696

9797
return 1;
9898
}
9999

100-
int _dos_setfileattr(char* name, short attr) {
100+
static int _dos_setfileattr(char* name, short attr) {
101101
printf("_dos_setfileattr(\"%s\", %d)\n", name, attr);
102102

103103
return 1;
@@ -117,12 +117,12 @@ char _getche() {
117117
return getchar();
118118
}
119119

120-
void dos_getdrive(Long* drv) {
120+
static void dos_getdrive(Long* drv) {
121121
// printf("dos_getdrive(%p)\n", drv );
122122
*drv = 1; // 1 = A:
123123
}
124124

125-
void dos_setdrive(Long drv, Long* dmy) {
125+
static void dos_setdrive(Long drv, Long* dmy) {
126126
// printf("dos_setdrive(%d, %p)\n", drv, dmy );
127127
}
128128

@@ -136,7 +136,7 @@ int kbhit() {
136136
return 1;
137137
}
138138

139-
char ungetch(char c) {
139+
static char ungetch(char c) {
140140
printf("ungetch()\n");
141141
return 0;
142142
}
@@ -161,7 +161,7 @@ static Long DosFgetc(ULong param) {
161161
if (finfop->onmemory.buffer) return (Long)fgetcFromOnmemory(finfop);
162162

163163
#ifdef _WIN32
164-
char c;
164+
char c = 0;
165165
DWORD read_len = 0;
166166
if (GetFileType(finfop->host.handle) == FILE_TYPE_CHAR) {
167167
/* 標準入力のハンドルがキャラクタタイプだったら、ReadConsoleを試してみる。*/
@@ -171,7 +171,8 @@ static Long DosFgetc(ULong param) {
171171
ReadConsoleInput(finfop->host.handle, &ir, 1, (LPDWORD)&read_len);
172172
if (b == FALSE) {
173173
/* コンソールではなかった。*/
174-
ReadFile(finfop->host.handle, &c, 1, (LPDWORD)&read_len, NULL);
174+
if (!ReadFile(finfop->host.handle, &c, 1, (LPDWORD)&read_len, NULL))
175+
c = 0;
175176
break;
176177
}
177178
if (read_len == 1 && ir.EventType == KEY_EVENT &&
@@ -181,7 +182,8 @@ static Long DosFgetc(ULong param) {
181182
}
182183
}
183184
} else {
184-
ReadFile(finfop->host.handle, &c, 1, (LPDWORD)&read_len, NULL);
185+
if (!ReadFile(finfop->host.handle, &c, 1, (LPDWORD)&read_len, NULL))
186+
c = 0;
185187
}
186188
return (read_len == 0) ? DOSE_ILGFNC : c;
187189
#else
@@ -470,7 +472,7 @@ bool dos_call(UByte code) {
470472
// 非リダイレクト
471473
WriteW32(1, finfop->host.handle, c, 1);
472474
} else {
473-
Long nwritten;
475+
Long nwritten = 0;
474476
/* Win32API */
475477
WriteFile(finfop->host.handle, c, 1, (LPDWORD)&nwritten, NULL);
476478
}
@@ -540,7 +542,7 @@ bool dos_call(UByte code) {
540542
if (GetConsoleMode(finfop->host.handle, &st) != 0) {
541543
WriteW32(1, finfop->host.handle, data_ptr, len);
542544
} else {
543-
Long nwritten;
545+
Long nwritten = 0;
544546
/* Win32API */
545547
WriteFile(finfop->host.handle, data_ptr, len, (LPDWORD)&nwritten,
546548
NULL);
@@ -1115,8 +1117,8 @@ static Long Dup2(short org, short new) {
11151117
*/
11161118
static Long Dskfre(short drv, Long buf) {
11171119
#ifdef _WIN32
1118-
ULong SectorsPerCluster, BytesPerSector, NumberOfFreeClusters,
1119-
TotalNumberOfClusters;
1120+
ULong SectorsPerCluster = 0, BytesPerSector = 0, NumberOfFreeClusters = 0,
1121+
TotalNumberOfClusters = 0;
11201122

11211123
BOOL b = GetDiskFreeSpaceA(
11221124
NULL, (LPDWORD)&SectorsPerCluster, (LPDWORD)&BytesPerSector,
@@ -1193,7 +1195,7 @@ static Long fgetsFromOnmemory(FILEINFO* finfop, ULong adr) {
11931195
戻り値:エラーコード
11941196
*/
11951197
static Long Fgets(Long adr, short hdl) {
1196-
char buf[257];
1198+
char buf[257] = {0};
11971199
size_t len;
11981200

11991201
FILEINFO* finfop = &finfo[hdl];
@@ -1208,8 +1210,8 @@ static Long Fgets(Long adr, short hdl) {
12081210
{
12091211
int i = 0;
12101212
while (i < max) {
1211-
DWORD read_len;
1212-
char c;
1213+
DWORD read_len = 0;
1214+
char c = 0;
12131215

12141216
if (ReadFile(finfop->host.handle, &c, 1, (LPDWORD)&read_len, NULL) ==
12151217
FALSE)
@@ -1263,7 +1265,7 @@ static Long Write(short hdl, Long buf, Long len) {
12631265
}
12641266

12651267
#ifdef _WIN32
1266-
unsigned len2;
1268+
unsigned len2 = 0;
12671269
WriteFile(finfo[hdl].host.handle, mem.bufptr, mem.length, &len2, NULL);
12681270
write_len = len2;
12691271
if (finfo[hdl].host.handle == GetStdHandle(STD_OUTPUT_HANDLE))
@@ -1563,25 +1565,24 @@ static Long Nfiles(Long buf) {
15631565
if (!mem.bufptr) throwBusErrorOnWrite(buf + mem.length);
15641566

15651567
#ifdef _WIN32
1566-
WIN32_FIND_DATA f_data;
1568+
WIN32_FIND_DATA f_data = {0};
15671569
char* buf_ptr = mem.bufptr;
15681570
short atr = buf_ptr[0]; /* 検索すべきファイルの属性 */
15691571

15701572
{
15711573
/* todo:buf_ptrの指す領域から必要な情報を取り出して、f_dataにコピーする。*/
15721574
/* 2秒→100nsに変換する。*/
1573-
SYSTEMTIME st;
1574-
unsigned short s;
1575-
1576-
s = *((unsigned short*)&buf_ptr[24]);
1577-
st.wYear = ((s & 0xfe00) >> 9) + 1980;
1578-
st.wMonth = (s & 0x01e0) >> 5;
1579-
st.wDay = (s & 0x1f);
1580-
s = *((unsigned short*)&buf_ptr[22]);
1581-
st.wHour = (s & 0xf800) >> 11;
1582-
st.wMinute = (s & 0x07e0) >> 5;
1583-
st.wSecond = (s & 0x001f);
1584-
st.wMilliseconds = 0;
1575+
unsigned short s1 = *((unsigned short*)&buf_ptr[24]);
1576+
unsigned short s2 = *((unsigned short*)&buf_ptr[22]);
1577+
SYSTEMTIME st = {
1578+
.wYear = ((s1 & 0xfe00) >> 9) + 1980,
1579+
.wMonth = (s1 & 0x01e0) >> 5,
1580+
.wDay = (s1 & 0x1f),
1581+
.wHour = (s2 & 0xf800) >> 11,
1582+
.wMinute = (s2 & 0x07e0) >> 5,
1583+
.wSecond = (s2 & 0x001f),
1584+
.wMilliseconds = 0,
1585+
};
15851586
SystemTimeToFileTime(&st, &f_data.ftLastWriteTime);
15861587

15871588
f_data.nFileSizeHigh = 0;
@@ -1673,15 +1674,16 @@ static Long Getdate() {
16731674
*/
16741675
static Long Setdate(short dt) {
16751676
#ifdef _WIN32
1676-
SYSTEMTIME stime;
1677-
BOOL b;
1678-
stime.wYear = (dt >> 9) & 0x7F + 1980;
1679-
stime.wMonth = (dt >> 5) & 0xF;
1680-
stime.wDay = dt & 0x1f;
1681-
stime.wSecond = 0;
1682-
stime.wMilliseconds = 0;
1683-
// b = SetSystemTime(&stime);
1684-
b = SetLocalTime(&stime);
1677+
SYSTEMTIME stime = {
1678+
.wYear = (dt >> 9) & 0x7F + 1980,
1679+
.wMonth = (dt >> 5) & 0xF,
1680+
.wDay = dt & 0x1f,
1681+
.wSecond = 0,
1682+
.wMilliseconds = 0,
1683+
};
1684+
1685+
// BOOL b = SetSystemTime(&stime);
1686+
BOOL b = SetLocalTime(&stime);
16851687
if (!b) return -14; /* パラメータ不正 */
16861688
#else
16871689
printf("DOSCALL SETDATE:not defined yet %s %d\n", __FILE__, __LINE__);
@@ -1731,14 +1733,15 @@ static Long Gettime(int flag) {
17311733
*/
17321734
static Long Settim2(Long tim) {
17331735
#ifdef _WIN32
1734-
SYSTEMTIME stime;
1735-
BOOL b;
1736-
stime.wYear = (tim >> 16) & 0x1F;
1737-
stime.wMonth = (tim >> 8) & 0x3F;
1738-
stime.wDay = tim & 0x3f;
1739-
stime.wSecond = 0;
1740-
stime.wMilliseconds = 0;
1741-
b = SetSystemTime(&stime);
1736+
SYSTEMTIME stime = {
1737+
.wYear = (tim >> 16) & 0x1F,
1738+
.wMonth = (tim >> 8) & 0x3F,
1739+
.wDay = tim & 0x3f,
1740+
.wSecond = 0,
1741+
.wMilliseconds = 0,
1742+
};
1743+
1744+
BOOL b = SetSystemTime(&stime);
17421745
if (!b) return -14; /* パラメータ不正 */
17431746
#else
17441747
printf("DOSCALL SETTIM2:not defined yet %s %d\n", __FILE__, __LINE__);
@@ -2374,7 +2377,7 @@ Long gets2(char* str, int max) {
23742377
}
23752378
if (c == EOF) str[cnt++] = EOF;
23762379
#ifdef _WIN32
2377-
unsigned dmy;
2380+
DWORD dmy = 0;
23782381
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), "\x01B[1A", 4, &dmy, NULL);
23792382
#endif
23802383
/* printf("%c[1A", 0x1B); */ /* カーソルを1行上に */

src/dostrace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static int codeToEscapeChar(int c) {
435435
#define STRING_MAX_WIDTH 32
436436

437437
static void dumpString(const char* s) {
438-
char buf[STRING_MAX_WIDTH + 16];
438+
char buf[STRING_MAX_WIDTH + 16] = {0};
439439
char* end = &buf[STRING_MAX_WIDTH];
440440
char* p = buf;
441441

@@ -590,7 +590,7 @@ static void printParam(const char* format, ULong* refParam) {
590590
}
591591
}
592592

593-
const char* printFormat(const char* format, ULong* refParam) {
593+
static const char* printFormat(const char* format, ULong* refParam) {
594594
while (format[0] != '\0') {
595595
const char* bracket = strchr(format, '{');
596596
if (bracket == NULL) break;

0 commit comments

Comments
 (0)