Skip to content

Commit 4fa62e4

Browse files
committed
20240328 -- minor patch. Added sanity checks when playing TZX blocks $19 and $2B
1 parent feee29d commit 4fa62e4

File tree

4 files changed

+113
-56
lines changed

4 files changed

+113
-56
lines changed

CSW0.C

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//@@//@@/@@ //@@/@@@/@@@/@@//@@//@@//@@//@@/@@ //@@ since 2020/05/31-09:50
77
//@@@@ //@@@@@//@@ //@@/@@@@@@ //@@@@//@@@@@ //@@@@ ------------------------
88

9-
#define MY_VERSION "20240224"
9+
#define MY_VERSION "20240328"
1010
#define MY_LICENSE "Copyright (C) 2020-2023 Cesar Nicolas-Gonzalez"
1111

1212
#define GPL_3_INFO \
@@ -39,7 +39,8 @@ Contact information: <mailto:cngsoft@gmail.com> */
3939
unsigned char buffer[512]; FILE *fi,*fo;
4040
char *autosuffix(char *t,char *s,char *x) // return a valid path, with a new suffix if required
4141
{
42-
if (t) return t; else if (!s) return NULL; else if ((char*)buffer!=s) strcpy(buffer,s);
42+
if (t) return t; else if (!s) return NULL;
43+
if ((char*)buffer!=s) strcpy(buffer,s);
4344
if ((t=strrchr(buffer,'.'))&&(!(s=strrchr(buffer,
4445
#ifdef _WIN32
4546
'\\'
@@ -52,16 +53,16 @@ char *autosuffix(char *t,char *s,char *x) // return a valid path, with a new suf
5253

5354
// I/O file operations, buffering and Intel lil-endian integer logic -------- //
5455

55-
#define fread1(t,i) fread(t,1,i,fi)
56-
#define fwrite1(t,i) fwrite(t,1,i,fo)
57-
#define fput1(n) fputc(n,fo)
56+
#define fread1(t,i) fread((t),1,(i),fi)
57+
#define fwrite1(t,i) fwrite((t),1,(i),fo)
58+
#define fput1(n) fputc((n),fo)
5859
int fput4(int i) { fput1(i); fput1(i>>8); fput1(i>>16); return fput1(i>>24); } // non-buffered!
5960

6061
unsigned char tsrc[1<<12],ttgt[1<<12]; int isrc=0,ilen=0,itgt=0; // I/O file buffers
6162
#define flush1() fwrite1(ttgt,itgt)
62-
int frecv1(void) { while (isrc>=ilen) if (isrc-=ilen,!(ilen=fread1(tsrc,sizeof(tsrc)))) return -1; return tsrc[isrc++]; }
63+
int frecv1(void) { while (isrc>=ilen) { if (isrc-=ilen,!(ilen=fread1(tsrc,sizeof(tsrc)))) return -1; } return tsrc[isrc++]; }
6364
int frecv4(void) { int i=frecv1(); i|=frecv1()<<8; i|=frecv1()<<16; return i|(frecv1()<<24); }
64-
int fsend1(int i) { ttgt[itgt++]=i; if (itgt>=length(ttgt)) { if (!flush1()) return -1; itgt=0; } return i; }
65+
int fsend1(int i) { ttgt[itgt++]=i; if (itgt>=length(ttgt)) { if (!flush1()) return -1; else itgt=0; } return i; }
6566
int fsend4(int i) { fsend1(i); fsend1(i>>8); fsend1(i>>16); return fsend1(i>>24); }
6667

6768
// the main procedure proper ------------------------------------------------ //
@@ -253,7 +254,7 @@ int main(int argc,char *argv[])
253254
// floor
254255
while (l) fsend1(128),--l;
255256
}
256-
if (itgt&1) fsend1(0); flush1(); // RIFF even-padding + flush!
257+
{ if (itgt&1) fsend1(0); } flush1(); // RIFF even-padding + flush!
257258
printf(ok_bytes,(int)ftell(fi),i=(int)ftell(fo));
258259
fseek(fo, 4,SEEK_SET); fput4(i-8); // file size-8 = chunk size+36
259260
fseek(fo,24,SEEK_SET); fput4(hz); fput4(hz); // clock + bandwidth

CSW2CDT-UI.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//@@//@@/@@ //@@/@@@/@@@/@@//@@//@@//@@//@@/@@ //@@ bits of CSW0 + CSW2CDT
77
//@@@@ //@@@@@//@@ //@@/@@@@@@ //@@@@//@@@@@ //@@@@ ------------------------
88

9-
#define MY_VERSION "20240224"
9+
#define MY_VERSION "20240328"
1010
#define MY_LICENSE "Copyright (C) 2020-2023 Cesar Nicolas-Gonzalez"
1111

1212
/* This notice applies to the source code of CSW2CDT and its binaries.
@@ -78,12 +78,12 @@ int OkTarget(HWND hwnd) // show the size of file `target`
7878
}
7979
int RunExe(HWND hwnd,char *s) // run a program and show a warning if required
8080
{
81-
sprintf(buffer,"%s %s \"%s\" \"%s\"",s,params,source,target);
81+
sprintf(buffer,"\"\"%s\" %s \"%s\" \"%s\"\"",s,params,source,target);
8282
return system(buffer)?WarningBox(hwnd,buffer),0:1;
8383
}
8484
int RunStdout(HWND hwnd,char *s) // run a program and send its output to `target`
8585
{
86-
sprintf(buffer,"%s %s \"%s\" nul > \"%s\"",s,params,source,target);
86+
sprintf(buffer,"\"\"%s\" %s \"%s\" nul > \"%s\"\"",s,params,source,target);
8787
return system(buffer)?WarningBox(hwnd,buffer),0:1;
8888
}
8989

0 commit comments

Comments
 (0)