Hi,
Trying to compile a program I received an Error 11 with a notification requesting that I please report the error.
My compiler options were:
cobc -std=cobol2014 -debug -W -fimplicit-init -O2 -c src/main/ff-via-printf.cob -o build/release/ff-via-printf-1.0.o
ff-via-printf.cob contains:
GNU *> >> source format is fixed
COBOL *> ***************************************************************
*> File: ff-via-printf.cob
*> SPDX-License-Identifier: MIT
*> Copyright (c) 2022, Justin Hanekom
*> Description: Writes two rows of float numbers to the output
*> file, outfile.
*>
*> ***************************************************************
*> Date Change Description
*> ====== ==================
*> jh2204 Initial release
*>
*> ***************************************************************
identification division.
id program-id. ff-via-printf.
site environment division.
configuration section.
repository.
function all intrinsic.
input-output section.
file-control.
select outfile-floats
assign to "floats.txt"
organization is line sequential
file status is ws01-outfile-status.
data data division.
file file section.
fd outfile-floats.
01 outfile-record pic x(80) value all spaces.
store working-storage section.
01 a01-row binary-long.
01 c01-result-success constant as 0.
01 c05-result-unknown-err constant as -1.
01 ws01-outfile-status pic x(2).
01 ws05-x-precision pic 9(2) value 0.
01 ws10-y-precision pic 9(2) value 0.
01 ws15-print-format pic x(15) value all spaces.
01 ws20-print-buffer pic x(80) value all spaces.
link linkage section.
01 l01-outfile-name pic x(11).
01 l05-num-rows binary-long.
01 l10-x-table.
05 l10-x-values occurs 0 to 100000 times
depending on l05-num-rows.
10 l10-x float-long.
01 l15-y-table.
05 l15-y-values occurs 0 to 100000 times
depending on l05-num-rows.
10 l15-y float-long.
01 l20-x-precision pic 9(2).
01 l25-y-precision pic 9(2).
01 l30-result binary-long.
/
*> ***************************************************************
code procedure division
using l01-outfile-name
l05-num-rows
l10-x-table
l15-y-table
l20-x-precision
l25-y-precision
l30-result
.
decl declaratives.
*> ---------------------------------------------------------------
*> The **outfile-floats-errors section responds to errors that
*> occur with outfile-floats.
*> ---------------------------------------------------------------
outfile-floats-errors section.
use after standard error on outfile-floats.
show-outfile-floats-error.
display "An error occurred with the outfile-floats file."
upon stderr
end-display
.
end declaratives.
*> ===============================================================
*> The **mainline** section is the program entry point.
*> ===============================================================
main mainline section.
perform 100-initialize
perform 200-print-arrays
perform 800-done
.
*> ===============================================================
*> The **100-initialize** section initializes any data division
*> entries that need to be initialized.
*> ===============================================================
init 100-initialize section.
>>D ready trace
move c05-result-unknown-err to l30-result
*> open output-floats
open output sharing with read only outfile-floats
if ws01-outfile-status greater than 10
perform 910-display-hard-exception
end-if
*> initialize the print format
move l20-x-precision to ws05-x-precision
move l25-y-precision to ws10-y-precision
string "%."
trim(ws05-x-precision)
"g" x"09" "%."
trim(ws10-y-precision)
"g"
into ws15-print-format
on overflow perform 910-display-hard-exception
>>D not on overflow
>>D display "Print formatting will be: "
>>D trim(ws15-print-format)
>>D upon stderr
>>D end-display
end-string
>>D reset trace
.
*> ===============================================================
*> The **200-print-arrays** section prints the `l05-num-rows`
*> values in the `l10-x-table` and `l15-y-table`, to the file
*> `l01outfile-name`. The x-vals are given the `l20-x-precision`
*> precision, and the y-vals the `l25-y-precision` precision.
*> ===============================================================
print 200-print-arrays section.
perform varying a01-row
from 1 by 1
until a01-row > l05-num-rows
move all spaces to ws20-print-buffer
call "sprintf"
using
by reference ws20-print-buffer
ws15-print-format
by value l10-x (a01-row)
l15-y (a01-row)
returning omitted
end-call
move ws20-print-buffer to outfile-record
write outfile-record end-write
>>D display
>>D l10-x (a01-row) " = " l15-y (a01-row)
>>D end-display
end-perform
.
*> ===============================================================
*> The **800-done** section finalizes the result sent to the
*> calling program and returns to the calling program.
*> ===============================================================
done 800-done section.
>>D ready trace
close outfile-floats
move c01-result-success to l30-result
>>D reset trace
perform 890-exit
.
*> ---------------------------------------------------------------
*> **890-exit** exists this program and returns to the calling
*> program.
*> ---------------------------------------------------------------
890-exit.
exit goback.
/
*> ===============================================================
*> **900-display-exception** provides details of warnings
*> and abends.
*> ===============================================================
900-display-exception section.
*> ---------------------------------------------------------------
*> **910-display-hard-exception** displays details of the hard
*> exception that has just occurred and then terminates the
*> program with the error result code `127`.
*> ---------------------------------------------------------------
fail 910-display-hard-exception.
perform 920-display-soft-exception
stop run returning 127
.
*> ---------------------------------------------------------------
*> **920-display-soft-exception** displays details of the
*> soft exception that has just occurred.
*> ---------------------------------------------------------------
warn 920-display-soft-exception.
display
"Exception-file: " exception-file
upon syserr
end-display
display
"Exception-status: " exception-status
upon syserr
end-display
display
"Exception-location: " exception-location
upon syserr
end-display
display
"Exception-statement: " exception-statement
upon syserr
end-display
.
end program ff-via-printf.
The compiler returns:
attempt to reference unallocated memory (signal SIGSEGV)
cobc: aborting compile of src/main/ff-via-printf.cob at line 103 (unknown: unknown)
cobc: Please report this!
Any help would be appreciated!
Regards,
Justin Hanekom
Diff:
Thank you Simon!
I am using cobc version 3.1.2.0 (i.e., prior to 3.2-dev).
Your answer explains why compiling this program with the additional options
" -O -DDEBUG -g -fdebugging-line -fdebugging-mode=ok -ftraceall"
for a debug version results in a successful compile.
BTW I am an old hand, having been a professional developer since 1986, so I
know only too well the value of a good bug report.
Kindest regards,
Justin
On Sun, May 15, 2022 at 2:41 PM Simon Sobisch sf-mensch@users.sourceforge.net wrote:
Related
Bugs:
#821Bugs:
#830Commit: [r4572]
Thank you for this good bug report.
This one is solved already in GnuCOBOL 3.2-dev - it happens when you should get some message about dialect specific issues - in this case
To get over the error add
-fdebugging-mode=okto your command line or compile with-std=default.The bug where this is tracked is [bugs:#821], solved by [r4572].
Related
Bugs:
#821Commit: [r4572]