From ad7c0e46f0b70f0e601b162411a3e95e788b45f1 Mon Sep 17 00:00:00 2001 From: Jonathan Campbell Date: Sun, 30 Oct 2016 09:38:35 -0700 Subject: [PATCH] fix bizarre near/far sprintf problem when gv->pee not initialized by just replacing the gv->pee status text buffer with a global char[] buffer everyone can use for status messages. that way Watcom C can resolve the far pointer properly to sprintf(). This fixes ZCROLL.EXE printing *** Null pointer assignment detected on shutdown. --- data/g.pal | Bin 768 -> 768 bytes src/lib/16_timer.c | 11 +++++++---- src/lib/scroll16.c | 11 +++++++++-- src/lib/scroll16.h | 2 ++ src/lib/typdefst.h | 3 ++- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/data/g.pal b/data/g.pal index d11fb0fce8180eac9c62887cec19e7232d8b6412..6b992816b96b9fbbd2d936eaf6dec3a107ef4b6e 100755 GIT binary patch delta 81 zcmZo*YhasT!>BgVw!%@!l1JJ~$eKrt+s0bXl*8J}oWBdUw!%@#oJZP9$&yEm+s0bXl*8J}oWkurokku.clock_start = *clockw; gv->kurokku.clock = clockw; //gv->kurokku.frames_per_second = 60; - gv->pee = _nmalloc(sizeof(byte)*16); - //turn this off if XT + + //turn this off if XT switch(detectcpu()) { case 0: @@ -63,6 +63,9 @@ double time_in_seconds(global_game_variables_t *gv) return (gv->kurokku.t) / CLOCKS_PER_SEC; } +// big global status text buffer +char global_temp_status_text[512]; + /*double time_in_seconds(time_t in_t) { return (in_t) / CLOCKS_PER_SEC; @@ -75,8 +78,8 @@ void shinkutxt(global_game_variables_t *gv) if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second)) { //t=(((*(gv->clock))-gv->clock_start) /18.2); - sprintf(gv->pee, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv)); - fprintf(stderr, "%s\n", gv->pee); + sprintf(global_temp_status_text, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv)); + fprintf(stderr, "%s\n", global_temp_status_text); //(gv->clock_start)=*(gv->clock); gv->kurokku.tiku=0; } diff --git a/src/lib/scroll16.c b/src/lib/scroll16.c index b94e768a..6f1c450e 100755 --- a/src/lib/scroll16.c +++ b/src/lib/scroll16.c @@ -774,9 +774,16 @@ void shinku(global_game_variables_t *gv) // vga_restore_rm0wm0(); if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second)) { - sprintf(gv->pee, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv)); + // NTS: For some bizarre reason, gv->pee is not initialized, but the pointer is not NULL even + // though it should be. Instead it's NULL as a near pointer but contains a non-null + // segment value, so testing against NULL doesn't work. It is initialized properly if + // you call start_timer() though which uses near malloc. Rather than fight with that, + // I decided it would be better to declare a temp buffer statically and sprintf to that. + // + // This fixes *** Null pointer assignment detected error message in ZCROLL.EXE on exit. + sprintf(global_temp_status_text, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv)); //modexClearRegion(&(gv->video.page[shinku_fps_indicator_page]), x, y, w, h, 45); - modexprint(&(gv->video.page[/*!*/(gv->video.p)]), x, y, type, col, bgcol, gv->pee); + modexprint(&(gv->video.page[/*!*/(gv->video.p)]), x, y, type, col, bgcol, global_temp_status_text); gv->kurokku.tiku=0; /* block copy to visible RAM from offscreen */ // vga_setup_wm1_block_copy(); diff --git a/src/lib/scroll16.h b/src/lib/scroll16.h index 1f609670..84b3eab0 100755 --- a/src/lib/scroll16.h +++ b/src/lib/scroll16.h @@ -70,6 +70,8 @@ typedef struct extern boolean pageflipflop, pageploop; extern unsigned char shinku_fps_indicator_page; +extern char global_temp_status_text[512]; + //map_t allocMap(int w, int h); //void initMap(map_t *map); void walk(map_view_t *pip, player_t *player, word pn); diff --git a/src/lib/typdefst.h b/src/lib/typdefst.h index 32aaed26..d6cc2b9a 100755 --- a/src/lib/typdefst.h +++ b/src/lib/typdefst.h @@ -334,10 +334,11 @@ typedef struct video_t video; // video settings variable ca_t ca; // ca stuff pm_t pm; // pm stuff - byte *pee; // message for fps loghandle_t handle; //handles for file logging kurokku_t kurokku; //clock struct mminfo_t mm; mminfotype mmi; } global_game_variables_t; +extern char global_temp_status_text[512]; + #endif /* _TYPEDEFSTRUCT_H_ */ -- 2.39.5