@@ -59,7 +59,7 @@ static Long Gets(Long);
5959static Long Kflush (short );
6060static Long Ioctrl (short , Long );
6161static Long Dup (short );
62- static Long Dup2 (short , short );
62+ static Long Dup2 (short org , short new );
6363static Long Dskfre (short , Long );
6464static Long Close (short );
6565static Long Fgets (Long , short );
@@ -91,13 +91,13 @@ static Long Exec3(ULong, Long, Long);
9191static 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 */
11161118static 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 */
11951197static 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 */
16741675static 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 */
17321734static 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行上に */
0 commit comments