From c38716f3b72694fff086ed6891bb0826e1b78647 Mon Sep 17 00:00:00 2001 From: Lynn Stricklan Date: Mon, 4 Jan 2021 20:08:02 -0700 Subject: [PATCH 1/8] Update libqb.cpp 2 changes here: line 13062: When opening a file for random access, if the LEN is not supplied, it defaults the length correctly, but does not allocate the buffer correctly. The code should reference the record_length in the file struct. Changes in lines 15798-15853: When printing text to the screen, carriage returns in the text are ignored. In sub_file_print, the code for printing to the screen is modified to honor carriage returns. --- internal/c/libqb.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index f53324d4b..3dc93c727 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -13059,7 +13059,7 @@ void sub_open(qbs *name,int32 type,int32 access,int32 sharing,int32 i,int64 reco if (type==1){//set record length f->record_length=128; if (passed) if (record_length!=-1) f->record_length=record_length; - f->field_buffer=(uint8*)calloc(record_length,1); + f->field_buffer=(uint8*)calloc(f->record_length,1); } if (type==5){//seek eof @@ -15798,8 +15798,11 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ //returns a string to advance to the horizontal position "pos" on either //the current line or the next line. static int32 w,div,cursor; + + static int32 cr_size; // a local in case file is SCRN + cr_size = tab_spc_cr_size; // init to caller's value //calculate width in spaces & current position - if (tab_spc_cr_size==2){ + if (cr_size==2){ //print to file div=1; w=2147483647; @@ -15810,9 +15813,14 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ if (i<0) goto invalid_file;//TCP/IP unsupported if (gfs_fileno_valid(i)!=1) goto invalid_file;//Bad file name or number i=gfs_fileno[i];//convert fileno to gfs index - cursor=gfs_file[i].column; + if (gfs_file[i].scrn == 1) { // going to screen, change the cr size + cr_size = 1; + } else { + cursor=gfs_file[i].column; + } invalid_file:; - }else{ + } + if (cr_size == 1) { //print to surface if (write_page->text){ w=write_page->width; @@ -15842,7 +15850,7 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ size=0; spaces=0; cr=0; if (cursor>pos){ cr=1; - size=tab_spc_cr_size; + size=cr_size; spaces=pos/div; if (pos%div) spaces++; spaces--;//don't put a space on the dest position size+=spaces; @@ -15853,8 +15861,8 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ //build custom string tqbs=qbs_new(size,1); if (cr){ - tqbs->chr[0]=13; if (tab_spc_cr_size==2) tqbs->chr[1]=10; - memset(&tqbs->chr[tab_spc_cr_size],32,spaces); + tqbs->chr[0]=13; if (cr_size==2) tqbs->chr[1]=10; + memset(&tqbs->chr[cr_size],32,spaces); }else{ memset(tqbs->chr,32,spaces); } From fb10bdb7f8e97cdea185ec5415c54cdf9bfedc72 Mon Sep 17 00:00:00 2001 From: Lynn Stricklan Date: Mon, 4 Jan 2021 20:16:15 -0700 Subject: [PATCH 2/8] Update msbin.c The processing for MKDMBF$ fails for numbers smaller than 1. Basic cause is the check for exponent overflow is incorrect. Changed code to correctly check for exponent overflow --- internal/c/msbin.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/c/msbin.c b/internal/c/msbin.c index 85890be91..f623b7ab4 100644 --- a/internal/c/msbin.c +++ b/internal/c/msbin.c @@ -214,7 +214,7 @@ int32 _dieeetomsbin(double *src8, double *dest8) /* Make a clobberable copy of the source number */ memcpy(ieee,src8,8); //strncpy((char *)ieee,(char *)src8,8); - for (i=0; i<8; i++) msbin[i] = 0; + memset(msbin, 0, sizeof(*dest8)); //for (i=0; i<8; i++) msbin[i] = 0; /* If all are zero in src8, the msbin should be zero */ for (i=0; i<8; i++) any_on |= ieee[i]; @@ -222,12 +222,15 @@ int32 _dieeetomsbin(double *src8, double *dest8) sign = ieee[7] & 0x80; msbin[6] |= sign; - msbin_exp = (unsigned)(ieee[7] & 0x7f) * 0x10; + msbin_exp = (unsigned)(ieee[7] & 0x7f) << 4; //(unsigned)(ieee[7] & 0x7f) * 0x10; msbin_exp += ieee[6] >> 4; - if (msbin_exp-0x3ff > 0x80) return 1; - - msbin[7] = msbin_exp - 0x3ff + 0x80 + 1; + // verify the exponent is in range for MBF encoding + msbin_exp = msbin_exp - 0x3ff + 0x80 + 1; + if ((msbin_exp & 0xff00) != 0) return 1; + msbin[7] = msbin_exp; + // if (msbin_exp-0x3ff > 0x80) return 1; + // msbin[7] = msbin_exp - 0x3ff + 0x80 + 1; /* The ieee mantissa must be shifted up 3 bits */ ieee[6] &= 0x0f; /* mask out the exponent in the second byte */ From ea4656d51c08cad50e41a924434991de163a09bd Mon Sep 17 00:00:00 2001 From: Lynn Stricklan Date: Tue, 5 Jan 2021 14:29:56 -0700 Subject: [PATCH 3/8] Revert "Update libqb.cpp" This reverts commit c38716f3b72694fff086ed6891bb0826e1b78647. --- internal/c/libqb.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index 3dc93c727..f53324d4b 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -13059,7 +13059,7 @@ void sub_open(qbs *name,int32 type,int32 access,int32 sharing,int32 i,int64 reco if (type==1){//set record length f->record_length=128; if (passed) if (record_length!=-1) f->record_length=record_length; - f->field_buffer=(uint8*)calloc(f->record_length,1); + f->field_buffer=(uint8*)calloc(record_length,1); } if (type==5){//seek eof @@ -15798,11 +15798,8 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ //returns a string to advance to the horizontal position "pos" on either //the current line or the next line. static int32 w,div,cursor; - - static int32 cr_size; // a local in case file is SCRN - cr_size = tab_spc_cr_size; // init to caller's value //calculate width in spaces & current position - if (cr_size==2){ + if (tab_spc_cr_size==2){ //print to file div=1; w=2147483647; @@ -15813,14 +15810,9 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ if (i<0) goto invalid_file;//TCP/IP unsupported if (gfs_fileno_valid(i)!=1) goto invalid_file;//Bad file name or number i=gfs_fileno[i];//convert fileno to gfs index - if (gfs_file[i].scrn == 1) { // going to screen, change the cr size - cr_size = 1; - } else { - cursor=gfs_file[i].column; - } + cursor=gfs_file[i].column; invalid_file:; - } - if (cr_size == 1) { + }else{ //print to surface if (write_page->text){ w=write_page->width; @@ -15850,7 +15842,7 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ size=0; spaces=0; cr=0; if (cursor>pos){ cr=1; - size=cr_size; + size=tab_spc_cr_size; spaces=pos/div; if (pos%div) spaces++; spaces--;//don't put a space on the dest position size+=spaces; @@ -15861,8 +15853,8 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ //build custom string tqbs=qbs_new(size,1); if (cr){ - tqbs->chr[0]=13; if (cr_size==2) tqbs->chr[1]=10; - memset(&tqbs->chr[cr_size],32,spaces); + tqbs->chr[0]=13; if (tab_spc_cr_size==2) tqbs->chr[1]=10; + memset(&tqbs->chr[tab_spc_cr_size],32,spaces); }else{ memset(tqbs->chr,32,spaces); } From 114288744385dcc2fe02f2589fff55b6fdce92ec Mon Sep 17 00:00:00 2001 From: Lynn Stricklan Date: Tue, 5 Jan 2021 14:39:18 -0700 Subject: [PATCH 4/8] Update libqb.cpp When opening a file for random access, if the LEN is not supplied, it defaults the length correctly, but does not allocate the buffer correctly. The code should reference the record_length in the file struct. --- internal/c/libqb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index f53324d4b..b2e7b250f 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -13059,7 +13059,7 @@ void sub_open(qbs *name,int32 type,int32 access,int32 sharing,int32 i,int64 reco if (type==1){//set record length f->record_length=128; if (passed) if (record_length!=-1) f->record_length=record_length; - f->field_buffer=(uint8*)calloc(record_length,1); + f->field_buffer=(uint8*)calloc(f->record_length,1); } if (type==5){//seek eof From ac9664e312b008cb683eebe57fe43353b4a65160 Mon Sep 17 00:00:00 2001 From: Lynn Stricklan Date: Mon, 4 Jan 2021 20:08:02 -0700 Subject: [PATCH 5/8] Update libqb.cpp 2 changes here: line 13062: When opening a file for random access, if the LEN is not supplied, it defaults the length correctly, but does not allocate the buffer correctly. The code should reference the record_length in the file struct. Changes in lines 15798-15853: When printing text to the screen, carriage returns in the text are ignored. In sub_file_print, the code for printing to the screen is modified to honor carriage returns. --- internal/c/libqb.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index da64aff9e..c7b70af91 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -13037,7 +13037,7 @@ void sub_open(qbs *name,int32 type,int32 access,int32 sharing,int32 i,int64 reco if (type==1){//set record length f->record_length=128; if (passed) if (record_length!=-1) f->record_length=record_length; - f->field_buffer=(uint8*)calloc(record_length,1); + f->field_buffer=(uint8*)calloc(f->record_length,1); } if (type==5){//seek eof @@ -15796,8 +15796,11 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ //returns a string to advance to the horizontal position "pos" on either //the current line or the next line. static int32 w,div,cursor; + + static int32 cr_size; // a local in case file is SCRN + cr_size = tab_spc_cr_size; // init to caller's value //calculate width in spaces & current position - if (tab_spc_cr_size==2){ + if (cr_size==2){ //print to file div=1; w=2147483647; @@ -15808,9 +15811,14 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ if (i<0) goto invalid_file;//TCP/IP unsupported if (gfs_fileno_valid(i)!=1) goto invalid_file;//Bad file name or number i=gfs_fileno[i];//convert fileno to gfs index - cursor=gfs_file[i].column; + if (gfs_file[i].scrn == 1) { // going to screen, change the cr size + cr_size = 1; + } else { + cursor=gfs_file[i].column; + } invalid_file:; - }else{ + } + if (cr_size == 1) { //print to surface if (write_page->text){ w=write_page->width; @@ -15840,7 +15848,7 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ size=0; spaces=0; cr=0; if (cursor>pos){ cr=1; - size=tab_spc_cr_size; + size=cr_size; spaces=pos/div; if (pos%div) spaces++; spaces--;//don't put a space on the dest position size+=spaces; @@ -15851,8 +15859,8 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ //build custom string tqbs=qbs_new(size,1); if (cr){ - tqbs->chr[0]=13; if (tab_spc_cr_size==2) tqbs->chr[1]=10; - memset(&tqbs->chr[tab_spc_cr_size],32,spaces); + tqbs->chr[0]=13; if (cr_size==2) tqbs->chr[1]=10; + memset(&tqbs->chr[cr_size],32,spaces); }else{ memset(tqbs->chr,32,spaces); } From f66559eed5f91d9b83bf12a5bdc5f4c8deab390e Mon Sep 17 00:00:00 2001 From: Lynn Stricklan Date: Mon, 4 Jan 2021 20:16:15 -0700 Subject: [PATCH 6/8] Update msbin.c The processing for MKDMBF$ fails for numbers smaller than 1. Basic cause is the check for exponent overflow is incorrect. Changed code to correctly check for exponent overflow --- internal/c/msbin.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/c/msbin.c b/internal/c/msbin.c index 85890be91..f623b7ab4 100644 --- a/internal/c/msbin.c +++ b/internal/c/msbin.c @@ -214,7 +214,7 @@ int32 _dieeetomsbin(double *src8, double *dest8) /* Make a clobberable copy of the source number */ memcpy(ieee,src8,8); //strncpy((char *)ieee,(char *)src8,8); - for (i=0; i<8; i++) msbin[i] = 0; + memset(msbin, 0, sizeof(*dest8)); //for (i=0; i<8; i++) msbin[i] = 0; /* If all are zero in src8, the msbin should be zero */ for (i=0; i<8; i++) any_on |= ieee[i]; @@ -222,12 +222,15 @@ int32 _dieeetomsbin(double *src8, double *dest8) sign = ieee[7] & 0x80; msbin[6] |= sign; - msbin_exp = (unsigned)(ieee[7] & 0x7f) * 0x10; + msbin_exp = (unsigned)(ieee[7] & 0x7f) << 4; //(unsigned)(ieee[7] & 0x7f) * 0x10; msbin_exp += ieee[6] >> 4; - if (msbin_exp-0x3ff > 0x80) return 1; - - msbin[7] = msbin_exp - 0x3ff + 0x80 + 1; + // verify the exponent is in range for MBF encoding + msbin_exp = msbin_exp - 0x3ff + 0x80 + 1; + if ((msbin_exp & 0xff00) != 0) return 1; + msbin[7] = msbin_exp; + // if (msbin_exp-0x3ff > 0x80) return 1; + // msbin[7] = msbin_exp - 0x3ff + 0x80 + 1; /* The ieee mantissa must be shifted up 3 bits */ ieee[6] &= 0x0f; /* mask out the exponent in the second byte */ From 69ab2d3327a3e3bfb6b5d4624093ca749e86f160 Mon Sep 17 00:00:00 2001 From: Lynn Stricklan Date: Tue, 5 Jan 2021 14:29:56 -0700 Subject: [PATCH 7/8] Revert "Update libqb.cpp" This reverts commit c38716f3b72694fff086ed6891bb0826e1b78647. --- internal/c/libqb.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index c7b70af91..da64aff9e 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -13037,7 +13037,7 @@ void sub_open(qbs *name,int32 type,int32 access,int32 sharing,int32 i,int64 reco if (type==1){//set record length f->record_length=128; if (passed) if (record_length!=-1) f->record_length=record_length; - f->field_buffer=(uint8*)calloc(f->record_length,1); + f->field_buffer=(uint8*)calloc(record_length,1); } if (type==5){//seek eof @@ -15796,11 +15796,8 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ //returns a string to advance to the horizontal position "pos" on either //the current line or the next line. static int32 w,div,cursor; - - static int32 cr_size; // a local in case file is SCRN - cr_size = tab_spc_cr_size; // init to caller's value //calculate width in spaces & current position - if (cr_size==2){ + if (tab_spc_cr_size==2){ //print to file div=1; w=2147483647; @@ -15811,14 +15808,9 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ if (i<0) goto invalid_file;//TCP/IP unsupported if (gfs_fileno_valid(i)!=1) goto invalid_file;//Bad file name or number i=gfs_fileno[i];//convert fileno to gfs index - if (gfs_file[i].scrn == 1) { // going to screen, change the cr size - cr_size = 1; - } else { - cursor=gfs_file[i].column; - } + cursor=gfs_file[i].column; invalid_file:; - } - if (cr_size == 1) { + }else{ //print to surface if (write_page->text){ w=write_page->width; @@ -15848,7 +15840,7 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ size=0; spaces=0; cr=0; if (cursor>pos){ cr=1; - size=cr_size; + size=tab_spc_cr_size; spaces=pos/div; if (pos%div) spaces++; spaces--;//don't put a space on the dest position size+=spaces; @@ -15859,8 +15851,8 @@ void sub_put2(int32 i,int64 offset,void *element,int32 passed){ //build custom string tqbs=qbs_new(size,1); if (cr){ - tqbs->chr[0]=13; if (cr_size==2) tqbs->chr[1]=10; - memset(&tqbs->chr[cr_size],32,spaces); + tqbs->chr[0]=13; if (tab_spc_cr_size==2) tqbs->chr[1]=10; + memset(&tqbs->chr[tab_spc_cr_size],32,spaces); }else{ memset(tqbs->chr,32,spaces); } From 87c01d0bedabd7241b925c0b96cb15be5b90e804 Mon Sep 17 00:00:00 2001 From: Lynn Stricklan Date: Tue, 5 Jan 2021 14:39:18 -0700 Subject: [PATCH 8/8] Update libqb.cpp When opening a file for random access, if the LEN is not supplied, it defaults the length correctly, but does not allocate the buffer correctly. The code should reference the record_length in the file struct. --- internal/c/libqb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index da64aff9e..16a345d0e 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -13037,7 +13037,7 @@ void sub_open(qbs *name,int32 type,int32 access,int32 sharing,int32 i,int64 reco if (type==1){//set record length f->record_length=128; if (passed) if (record_length!=-1) f->record_length=record_length; - f->field_buffer=(uint8*)calloc(record_length,1); + f->field_buffer=(uint8*)calloc(f->record_length,1); } if (type==5){//seek eof