commit 6af79f6
Devine Lu Linvega
·
2025-01-22 04:07:17 +0000 UTC
parent c9b06bd
(file.c) Moved length checks inside functions
1 files changed,
+8,
-13
+8,
-13
1@@ -191,8 +191,11 @@ file_init(UxnFile *c, char *filename, size_t max_len, int override_sandbox)
2 }
3
4 static Uint16
5-file_read(UxnFile *c, void *dest, int len)
6+file_read(UxnFile *c, Uint16 addr, int len)
7 {
8+ void *dest = &uxn.ram[addr];
9+ if(len > 0x10000 - addr)
10+ len = 0x10000 - addr;
11 if(c->outside_sandbox) return 0;
12 if(c->state != FILE_READ && c->state != DIR_READ) {
13 file_reset(c);
14@@ -243,11 +246,10 @@ ensure_parent_dirs(char *p)
15 static Uint16
16 file_write(UxnFile *c, Uint16 addr, Uint16 len, Uint8 flags)
17 {
18- void *src;
19+ void *src = &uxn.ram[addr];
20 Uint16 ret = 0;
21 if(len > 0x10000 - addr)
22 len = 0x10000 - addr;
23- src = &uxn.ram[addr];
24 if(c->outside_sandbox) return 0;
25 ensure_parent_dirs(c->current_filename);
26 if(c->state != FILE_WRITE && c->state != DIR_WRITE) {
27@@ -291,11 +293,10 @@ stat_size(Uint8 *dest, Uint16 len, off_t size)
28 static Uint16
29 file_stat(UxnFile *c, Uint16 addr, Uint16 len)
30 {
31- void *dest;
32+ void *dest = &uxn.ram[addr];
33 struct stat st;
34 if(len > 0x10000 - addr)
35 len = 0x10000 - addr;
36- dest = &uxn.ram[addr];
37 if(c->outside_sandbox)
38 return 0;
39 else if(stat(c->current_filename, &st))
40@@ -340,10 +341,7 @@ file_deo(Uint8 port)
41 break;
42 case 0xad:
43 addr = PEEK2(&uxn.dev[0xac]);
44- len = rL1;
45- if(len > 0x10000 - addr)
46- len = 0x10000 - addr;
47- res = file_read(&uxn_file[0], &uxn.ram[addr], len);
48+ res = file_read(&uxn_file[0], addr, rL1);
49 POKE2(&uxn.dev[0xa2], res);
50 break;
51 case 0xaf:
52@@ -371,10 +369,7 @@ file_deo(Uint8 port)
53 break;
54 case 0xbd:
55 addr = PEEK2(&uxn.dev[0xbc]);
56- len = rL2;
57- if(len > 0x10000 - addr)
58- len = 0x10000 - addr;
59- res = file_read(&uxn_file[1], &uxn.ram[addr], len);
60+ res = file_read(&uxn_file[1], addr, rL2);
61 POKE2(&uxn.dev[0xb2], res);
62 break;
63 case 0xbf: