diff --git a/ChangeLog b/ChangeLog index 21d93b899..ab1e792a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,14 +1,20 @@ +2024-09-29 Simon Sobisch + + * configure.ac: drop COB_LI_IS_LL in favor of existing COB_32_BIT_LONG + * configure.ac (cjson=local): use CJSON_CFLAGS and CJSON_LIBS also for + this case, fix include not to use quotes + 2024-09-27 Simon Sobisch - * build_aux/ltmain.sh, m4/libtool.m4, m4/ltoptions.m4, m4/ltversion.m4: - update libtool from 2.46 to 2.53, dropping all manual patches - * configure.ac: require autoconf 2.70 and drop check for lex-library with + * configure.ac: require autoconf 2.70 and drop check for lex-library with noyywrap option for AC_PROG_LEX * HACKING: document dependencies autoconf 2.70 and automake 1.16 and several smaller text updates * Makefile.am (checkmanual-code-coverage, checkall-code-coverage): new targets removing the need to do that manually + * build_aux/ltmain.sh, m4/libtool.m4, m4/ltoptions.m4, m4/ltversion.m4: + update libtool from 2.46 to 2.53, dropping all manual patches * DEPENDENCIES: added perl for running NIST85 2024-09-09 Simon Sobisch diff --git a/Makefile.am b/Makefile.am index d92eb165b..266d6f889 100644 --- a/Makefile.am +++ b/Makefile.am @@ -166,9 +166,9 @@ vcs-update: distbin distbin-gzip distbin-bzip2 distbin-lzip distbin-xz test: all - cd tests && $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) test + $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C tests test checkmanual: all - cd tests && $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) checkmanual + $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C tests checkmanual checkall: check test diff --git a/build_windows/config.h.in b/build_windows/config.h.in index e294ff951..d7294dc64 100644 --- a/build_windows/config.h.in +++ b/build_windows/config.h.in @@ -306,10 +306,6 @@ #define COB_LIBS "libcob.l" #endif - -/* long int is long long */ -/* #undef COB_LI_IS_LL */ - /* Module extension */ #define COB_MODULE_EXT "dll" diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 0bcd3a6db..758de798d 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -1,8 +1,14 @@ +2024-09-29 Simon Sobisch + + * cobc.c (cobc_print_info): drop COB_LI_IS_LL + in favor of existing COB_32_BIT_LONG + 2024-09-27 Simon Sobisch * plex.l, scanner.l: use noyywrap option instead of manually defining related code parts + * typeck.c (cb_tree_list_has_numeric_ref_or_field): cleanup 2024-09-25 Nicolas Berthier @@ -13,6 +19,11 @@ * typeck.c (cb_emit_move, cb_emit_set_to): do not check for incompatible data if no receiver field is of category numeric or numeric edited +2024-09-03 Simon Sobisch + + * typeck.c (cb_emit_accept): always check position + * cobc.c, flag.def: make scope optional for -fdump + 2024-08-28 David Declerck * tree.c (char_to_precedence_idx, get_char_type_description, valid_char_order): diff --git a/cobc/cobc.c b/cobc/cobc.c index f44c62f75..1ab3214bc 100644 --- a/cobc/cobc.c +++ b/cobc/cobc.c @@ -2704,7 +2704,7 @@ cobc_print_info (void) cobc_var_print ("64bit-mode", _("no"), 0); #endif -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG cobc_var_print ("BINARY-C-LONG", _("8 bytes"), 0); #else cobc_var_print ("BINARY-C-LONG", _("4 bytes"), 0); @@ -2797,7 +2797,7 @@ cobc_def_dump_opts (const char *opt, const int on) int dump_to_set; cb_old_trace = 0; /* Use new methods */ - if (!cb_strcasecmp (opt, "ALL")) { + if (!opt || !cb_strcasecmp (opt, "ALL")) { if (on) { cb_flag_dump = COB_DUMP_ALL; } else { @@ -3287,7 +3287,7 @@ process_command_line (const int argc, char **argv) break; case CB_FLAG_GETOPT_DUMP: - /* -fdump= : Add sections for dump code generation */ + /* -fdump[=] : Add sections for dump code generation */ cobc_def_dump_opts (cob_optarg, 1); break; diff --git a/cobc/flag.def b/cobc/flag.def index ad6f720c5..96c8765ab 100644 --- a/cobc/flag.def +++ b/cobc/flag.def @@ -82,9 +82,10 @@ CB_FLAG_NQ (0, "ec", CB_FLAG_GETOPT_EC, CB_FLAG_NQ (0, "no-ec", CB_FLAG_GETOPT_NO_EC, " -fno-ec=\tdisable code generation for ") -CB_FLAG_NQ (1, "dump", CB_FLAG_GETOPT_DUMP, +CB_FLAG_OP (1, "dump", CB_FLAG_GETOPT_DUMP, _(" -fdump= dump data fields on abort, may be\n" - " a combination of: ALL, WS, LS, RD, FD, SC, LO")) + " a combination of: ALL, WS, LS, RD, FD, SC, LO\n" + " default if no scope specified: ALL")) CB_FLAG_OP (0, "no-dump", CB_FLAG_GETOPT_NO_DUMP, _(" -fno-dump= exclude data fields from dumping on abort, may\n" " be a combination of: ALL, WS, LS, RD, FD, SC, LO\n" diff --git a/cobc/typeck.c b/cobc/typeck.c index 391ebaba5..3f87068dd 100644 --- a/cobc/typeck.c +++ b/cobc/typeck.c @@ -1056,7 +1056,8 @@ cb_emit_list (cb_tree l) } static COB_INLINE COB_A_INLINE int -cb_tree_is_numeric_ref_or_field (cb_tree x, int include_numeric_edited) { +cb_tree_is_numeric_ref_or_field (cb_tree x, int include_numeric_edited) +{ int cat; if (!x || !CB_REF_OR_FIELD_P (x)) { return 0; @@ -1067,8 +1068,9 @@ cb_tree_is_numeric_ref_or_field (cb_tree x, int include_numeric_edited) { } static int -cb_tree_list_has_numeric_ref_or_field (cb_tree l) { - for (l; +cb_tree_list_has_numeric_ref_or_field (cb_tree l) +{ + for (; l && !cb_tree_is_numeric_ref_or_field (CB_VALUE (l), 1); l = CB_CHAIN (l)); return (l != NULL); @@ -3939,6 +3941,7 @@ validate_alphabet (cb_tree alphabet) ap->high_val_char = maxchar; alphabet_valid = 1; + n = 0; /* keep analyzer happy */ for (l = ap->custom_list; l; l = CB_CHAIN (l)) { x = CB_VALUE (l); @@ -8258,7 +8261,9 @@ cb_emit_accept (cb_tree var, cb_tree pos, struct cb_attr_struct *attr_ptr) if (cb_listing_xref) { cobc_xref_set_receiving (var); } - + if (cb_validate_one (pos)) { + return; + } if (attr_ptr) { fgc = attr_ptr->fgc; bgc = attr_ptr->bgc; @@ -8270,8 +8275,7 @@ cb_emit_accept (cb_tree var, cb_tree pos, struct cb_attr_struct *attr_ptr) cursor = attr_ptr->cursor; color = attr_ptr->color; disp_attrs = attr_ptr->dispattrs; - if (cb_validate_one (pos) - || cb_validate_one (fgc) + if (cb_validate_one (fgc) || cb_validate_one (bgc) || cb_validate_one (scroll) || cb_validate_one (timeout) diff --git a/configure.ac b/configure.ac index d17fe1540..b7a516ab0 100644 --- a/configure.ac +++ b/configure.ac @@ -174,7 +174,6 @@ AH_TEMPLATE([COB_EXE_EXT], [Executable extension]) AH_TEMPLATE([COB_KEYWORD_INLINE], [Keyword for inline]) AH_TEMPLATE([COB_NO_SELFOPEN], [Can not dlopen self]) AH_TEMPLATE([COB_COMPUTED_GOTO], [Compilation of computed gotos works]) -AH_TEMPLATE([COB_LI_IS_LL], [long int is long long]) AH_TEMPLATE([COB_32_BIT_LONG], [long int is 32 bits]) AH_TEMPLATE([COB_64_BIT_POINTER], [Pointers are longer than 32 bits]) AH_TEMPLATE([WITH_CURSES], [curses library for extended SCREEN I/O]) @@ -999,7 +998,7 @@ AS_IF([test "$with_xml2" = yes -o "$with_xml2" = check], [ XML2_LIBS="-lxml2" fi LIBS="$LIBS $LIBCOB_LIBS_extern $XML2_LIBS" - # note: PKG_CONFIG and xml2-config set -I /path/to/libxml2 which contains a "libxml" folder where + # note: PKG_CONFIG and xml2-config set -I/path/to/libxml2 which contains a "libxml" folder where # all the files we look for are included for header in xmlwriter xmlversion uri parser tree; do AC_CHECK_HEADER([libxml/$header.h], [], @@ -1080,8 +1079,8 @@ AS_IF([test "$USE_JSON" = "cjson" -o "$USE_JSON" = "local" -o "$USE_JSON" = chec with_cjson_local=no AS_IF([test -e ./libcob/cJSON.c], [AC_MSG_CHECKING([whether linking of ./libcob/cJSON.c works]) - CPPFLAGS="$curr_cppflags -I./libcob" - LIBS="$LIBS $LIBCOB_LIBS_extern" + CPPFLAGS="$curr_cppflags -I./libcob $CJSON_CFLAGS" + LIBS="$LIBS $LIBCOB_LIBS_extern $CJSON_LIBS" AC_LINK_IFELSE([ AC_LANG_PROGRAM([[#include "cJSON.c"]], [[#if (CJSON_VERSION_MAJOR * 100 + CJSON_VERSION_MINOR) < 103 @@ -1098,8 +1097,8 @@ AS_IF([test "$USE_JSON" = "cjson" -o "$USE_JSON" = "local" -o "$USE_JSON" = chec if test "$with_cjson_local" = no; then AS_IF([test -e "$srcdir/libcob/cJSON.c"], [AC_MSG_CHECKING([whether linking of "$srcdir/libcob/cJSON.c" works]) - CPPFLAGS="$curr_cppflags -I\"$srcdir/libcob\"" - LIBS="$LIBS $LIBCOB_LIBS_extern" + CPPFLAGS="$curr_cppflags -I$srcdir/libcob $CJSON_CFLAGS" + LIBS="$LIBS $LIBCOB_LIBS_extern $CJSON_LIBS" AC_LINK_IFELSE([ AC_LANG_PROGRAM([[#include "cJSON.c"]], [[#if (CJSON_VERSION_MAJOR * 100 + CJSON_VERSION_MINOR) < 103 @@ -1108,7 +1107,7 @@ AS_IF([test "$USE_JSON" = "cjson" -o "$USE_JSON" = "local" -o "$USE_JSON" = chec cJSON_CreateNull ();]])], [AC_MSG_RESULT([yes]) AC_DEFINE([WITH_CJSON], [1]) - with_cjson_local="yes (in \"$srcdir/libcob\")"], + with_cjson_local="yes (in $srcdir/libcob)"], [AC_MSG_RESULT([no])] ) LIBS="$curr_libs"] @@ -1933,11 +1932,6 @@ AC_CHECK_SIZEOF(long long) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(void *) -AC_MSG_CHECKING([whether size of long int = size of long long]) -AS_IF([test "$ac_cv_sizeof_long_int" = "$ac_cv_sizeof_long_long"], - [AC_DEFINE([COB_LI_IS_LL], [1]) AC_MSG_RESULT([yes])], - [AC_MSG_RESULT([no])]) - AC_MSG_CHECKING([whether long is 32 bits]) AS_IF([test "$ac_cv_sizeof_long" = 4], [AC_DEFINE([COB_32_BIT_LONG], [1]) AC_MSG_RESULT([yes])], diff --git a/libcob/ChangeLog b/libcob/ChangeLog index 26dadfe99..9056a9101 100644 --- a/libcob/ChangeLog +++ b/libcob/ChangeLog @@ -1,4 +1,9 @@ +2024-09-29 Simon Sobisch + + * numeric.c, common.c (print_info_detailed): drop COB_LI_IS_LL + in favor of existing COB_32_BIT_LONG + 2024-07-27 Chuck Haatvedt * screenio.c: In preparation for Multiple Window support @@ -31,6 +36,20 @@ * screenio.c (cob_settings_screenio): implemented runtime config to hide the cursor +2024-08-11 Simon Sobisch + + * fileio.c (cob_fd_file_open) [_WIN32]: workaround for MinGW bug in locking + +2024-08-09 Simon Sobisch + + * common.h, common.c (cob_cleanup_thread): fix declaration + * common.c: drop includes found in coblocal.h + * common.c (cob_alloc_module): changed type and name of cob_mod_ptr + +2024-08-06 Simon Sobisch + + * intrinsic.c: speedup for NUMVAL related functions + 2024-07-29 Chuck Haatvedt * move.c (optimized_move_display_to_edited): fixed small bug @@ -84,10 +103,10 @@ 2024-05-30 Chuck Haatvedt - fix errors caught by the Sanitizer functionality of GCC. This - change did not resolve all of the issues found as some of them - were in Berkeley DB and some were intentional in the memory - corruption logic which has been implemented in the runtime. + fix errors caught by the Sanitizer functionality of GCC. This + change did not resolve all of the issues found as some of them + were in Berkeley DB and some were intentional in the memory + corruption logic which has been implemented in the runtime. * move.c (the cob_move_display_to_packed function was rewritten to fix the out of bounds memory addressing issues and also to make @@ -97,8 +116,8 @@ 2024-05-30 Chuck Haatvedt - fix errors in filio.c when building with VISAM 2.2. This issue - occurred when using a partial key with a sequential read previous. + fix errors in filio.c when building with VISAM 2.2. This issue + occurred when using a partial key with a sequential read previous. * fileio.c (indexed_start_internal), (indexed_start) and (indexed_read_next): added a new field, partial_key_length, @@ -129,7 +148,7 @@ 2024-07-19 Simon Sobisch - * coblocal.h (COB_TLS): add a new attribute for thread local static. + * coblocal.h (COB_TLS): add a new attribute for thread local static * common.h, common.c (cob_cleanup_thread): add a cleanup function for threads 2024-05-15 Simon Sobisch @@ -167,8 +186,9 @@ * fileio.c (cob_path_to_absolute): extracted from insert and cob_set_main_argv0 -2024-03-10 Alfredo Tupone +2024-01-31 Gwyn Ciesla + Bug #941 build issue * common.c: add missing include libxml/parser.h 2024-02-26 Boris Eng @@ -776,7 +796,7 @@ after suggestions by Chuck Haatvedt * termio.c (pretty_display_numeric): fix GCC warning with {{ 0 }} * termio.c (display_alnum_dump): slightly rewritten to fix compiler warnings - * cconv.c (cob_load_collation), common.c, intrinisic.c (cob_intr_random), + * cconv.c (cob_load_collation), common.c, intrinsic.c (cob_intr_random), termio.c: minor adjustments to fix compiler warnings * fileio.c (copy_fcd_to_file): fixed memory issues with writing to assign and select name @@ -836,7 +856,7 @@ after suggestions by Chuck Haatvedt * common.c (cob_move_packed_to_display, cob_packed_get_int, cob_packed_get_long_long): minor performance improvements and similar code to numeric.c - * intrinisic.c (calculate_start_end_for_numval): only skip leading spaces + * intrinsic.c (calculate_start_end_for_numval): only skip leading spaces and zeros, but not leading low-values 2023-01-25 Simon Sobisch @@ -1136,8 +1156,8 @@ after suggestions by Chuck Haatvedt 2022-10-17 Simon Sobisch * common.c (cob_debug_open, cob_trace_print), intrinsic.c - (cob_intr_hex_to_char): prefer extending switch over use of topupper - * call.c, common.c, intrinisic.c, screenio.c: directly call toupper/tolower + (cob_intr_hex_to_char): prefer extending switch over use of topupper + * call.c, common.c, intrinsic.c, screenio.c: directly call toupper/tolower without previous check of islower/isupper * system.def, common.c (cob_sys_runtime_error_proc): implement CBL_RUNTIME_ERROR diff --git a/libcob/coblocal.h b/libcob/coblocal.h index 5fa04d7f9..11eaf23fd 100644 --- a/libcob/coblocal.h +++ b/libcob/coblocal.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2007-2012, 2014-2023 Free Software Foundation, Inc. + Copyright (C) 2007-2012, 2014-2024 Free Software Foundation, Inc. Written by Roger While, Simon Sobisch, Ron Norman This file is part of GnuCOBOL. @@ -22,6 +22,8 @@ #ifndef COB_LOCAL_H #define COB_LOCAL_H +#pragma once + /* We use this file to define/prototype things that should not be exported to user space */ diff --git a/libcob/common.c b/libcob/common.c index 7ecf0c926..c6a83ac25 100644 --- a/libcob/common.c +++ b/libcob/common.c @@ -29,14 +29,10 @@ #endif #endif -#include #include #include #include #include -#ifdef HAVE_STRINGS_H -#include -#endif #include #include #include @@ -277,7 +273,7 @@ const int MAX_MODULE_ITERS = 10240; struct cob_alloc_module { struct cob_alloc_module *next; /* Pointer to next */ - void *cob_pointer; /* Pointer to malloced space */ + cob_module *cob_mod_ptr; /* Pointer to malloced module space */ }; /* EXTERNAL structure */ @@ -785,7 +781,7 @@ cob_exit_common_modules (void) - currently used for: decimals - and remove it from the internal module list */ for (ptr = cob_module_list; ptr; ptr = nxt) { - mod = ptr->cob_pointer; + mod = ptr->cob_mod_ptr; nxt = ptr->next; if (mod && mod->module_cancel.funcint) { mod->module_active = 0; @@ -3247,7 +3243,7 @@ cob_module_global_enter (cob_module **module, cob_global **mglobal, *module = cob_cache_malloc (sizeof (cob_module)); /* Add to list of all modules activated */ mod_ptr = cob_malloc (sizeof (struct cob_alloc_module)); - mod_ptr->cob_pointer = *module; + mod_ptr->cob_mod_ptr = *module; mod_ptr->next = cob_module_list; cob_module_list = mod_ptr; #if 0 /* cob_call_name_hash and cob_call_from_c are rw-branch only features @@ -3329,7 +3325,7 @@ cob_module_free (cob_module **module) prv = NULL; /* Remove from list of all modules activated */ for (ptr = cob_module_list; ptr; ptr = ptr->next) { - if (ptr->cob_pointer == *module) { + if (ptr->cob_mod_ptr == *module) { if (prv == NULL) { cob_module_list = ptr->next; } else { @@ -3341,7 +3337,8 @@ cob_module_free (cob_module **module) prv = ptr; } -#if 0 /* cob_module->param_buf and cob_module->param_field are rw-branch only features +#if 0 /* cob_module->param_buf and cob_module->param_field are + trunk (previously rw-branch) only features for now - TODO: activate on merge of r1547 */ && !cobglobptr->cob_call_from_c if ((*module)->param_buf != NULL) @@ -9769,7 +9766,7 @@ print_info_detailed (const int verbose) var_print ("64bit-mode", _("no"), "", 0); #endif -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG var_print ("BINARY-C-LONG", _("8 bytes"), "", 0); #else var_print ("BINARY-C-LONG", _("4 bytes"), "", 0); @@ -11221,7 +11218,8 @@ init_statement_list (void) } #endif -void cob_cleanup_thread () +void +cob_cleanup_thread (void) { cob_exit_strings (); } diff --git a/libcob/common.h b/libcob/common.h index cbdbadff6..c268eed79 100644 --- a/libcob/common.h +++ b/libcob/common.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2012, 2014-2023 Free Software Foundation, Inc. + Copyright (C) 2002-2012, 2014-2024 Free Software Foundation, Inc. Written by Keisuke Nishida, Roger While, Simon Sobisch, Ron Norman, Edward Hart @@ -22,6 +22,8 @@ #ifndef COB_COMMON_H #define COB_COMMON_H +#pragma once + #include /* for size_t */ /* Only define cob_decimal if we have the necessary mpz_t from gmp.h/mpir.h @@ -1682,7 +1684,7 @@ COB_EXPIMP void cob_runtime_hint (const char *, ...) COB_A_FORMAT12; COB_EXPIMP void cob_runtime_error (const char *, ...) COB_A_FORMAT12; COB_EXPIMP void cob_runtime_warning (const char *, ...) COB_A_FORMAT12; -COB_EXPIMP void cob_cleanup_thread (); +COB_EXPIMP void cob_cleanup_thread (void); /* General functions */ diff --git a/libcob/fileio.c b/libcob/fileio.c index e3d8a51b0..f5bbc61cf 100644 --- a/libcob/fileio.c +++ b/libcob/fileio.c @@ -1824,12 +1824,17 @@ cob_fd_file_open (cob_file *f, char *filename, HANDLE osHandle = (HANDLE)_get_osfhandle (fd); if (osHandle != INVALID_HANDLE_VALUE) { DWORD flags = LOCKFILE_FAIL_IMMEDIATELY; - OVERLAPPED fromStart = {0}; + OVERLAPPED fromStart = { 0 }; if (mode != COB_OPEN_INPUT) flags |= LOCKFILE_EXCLUSIVE_LOCK; if (!LockFileEx (osHandle, flags, 0, MAXDWORD, MAXDWORD, &fromStart)) { - f->open_mode = COB_OPEN_CLOSED; - close (fd); - return COB_STATUS_61_FILE_SHARING; + DWORD err = GetLastError (); + /* normally that return value would not happen, we use it to + work around call errors happening on MSYS */ + if (err != ERROR_INVALID_FUNCTION) { + f->open_mode = COB_OPEN_CLOSED; + close (fd); + return COB_STATUS_61_FILE_SHARING; + } } } } @@ -2087,10 +2092,15 @@ cob_file_open (cob_file *f, char *filename, OVERLAPPED fromStart = {0}; if (mode != COB_OPEN_INPUT) flags |= LOCKFILE_EXCLUSIVE_LOCK; if (!LockFileEx (osHandle, flags, 0, MAXDWORD, MAXDWORD, &fromStart)) { - f->open_mode = COB_OPEN_CLOSED; - f->fd = -1; - fclose (fp); - return COB_STATUS_61_FILE_SHARING; + DWORD err = GetLastError (); + /* normally that return value would not happen, we use it to + work around call errors happening on MSYS */ + if (err != ERROR_INVALID_FUNCTION) { + f->open_mode = COB_OPEN_CLOSED; + fclose (fp); + f->fd = -1; + return COB_STATUS_61_FILE_SHARING; + } } } } @@ -7074,7 +7084,7 @@ cob_savekey (cob_file *f, int idx, unsigned char *data) /* System routines */ /* stores the field's rtrimmed string content into a fresh allocated - string, which later needs to be passed to cob_free */ + string, which later needs to be passed to cob_free */ static void * cob_str_from_fld (const cob_field *f) { @@ -7104,7 +7114,7 @@ cob_str_from_fld (const cob_field *f) } while (data <= end) { -#if 0 /* Quotes in file */ +#if 0 /* Quotes in file, per MF, stopping at first space outside */ if (*data == '"') { quote_switch = !quote_switch; data++; diff --git a/libcob/intrinsic.c b/libcob/intrinsic.c index 785fa3b1b..727f7f6f6 100644 --- a/libcob/intrinsic.c +++ b/libcob/intrinsic.c @@ -716,6 +716,7 @@ int cob_check_numval_f (const cob_field *srcfield) { unsigned char *p = srcfield->data; + const unsigned int fsize = (unsigned int)srcfield->size; size_t plus_minus; size_t digits; size_t decimal_seen; @@ -724,10 +725,10 @@ cob_check_numval_f (const cob_field *srcfield) size_t break_needed; size_t exponent; size_t e_plus_minus; - int n; + unsigned int n; const unsigned char dec_pt = COB_MODULE_PTR->decimal_point; - if (!srcfield->size) { + if (!fsize) { return 1; } @@ -743,7 +744,7 @@ cob_check_numval_f (const cob_field *srcfield) e_plus_minus = 0; /* Check leading positions */ - for (n = 0; n < (int)srcfield->size; ++n, ++p) { + for (n = 0; n < fsize; ++n, ++p) { switch (*p) { case '0': case '1': @@ -781,11 +782,11 @@ cob_check_numval_f (const cob_field *srcfield) } } - if (n == (int)srcfield->size) { + if (n == fsize) { return n + 1; } - for (; n < (int)srcfield->size; ++n, ++p) { + for (; n < fsize; ++n, ++p) { switch (*p) { case '0': case '1': @@ -1445,7 +1446,7 @@ calculate_start_end_for_numval (cob_field *srcfield, unsigned char **pp, unsigned char **pp_end) { unsigned char *p = srcfield->data; - unsigned char *p_end; + register unsigned char *p_end; if (srcfield->size == 0 || p == NULL) { @@ -1479,7 +1480,7 @@ enum numval_type { static cob_field * numval (cob_field *srcfield, cob_field *currency, const enum numval_type type) { - unsigned char *final_buff = NULL; + unsigned char final_buff [COB_MAX_DIGITS + 1] = { 0 }; unsigned char *p, *p_end; unsigned char *currency_data = NULL; size_t datasize; @@ -1511,14 +1512,19 @@ numval (cob_field *srcfield, cob_field *currency, const enum numval_type type) cob_alloc_set_field_uint (0); return curr_field; } - /* not wasting buffer space (COBOL2022: 35/34 max)... */ + /* not wasting buffer space (COBOL2023: 35/34 max)... */ if (datasize > COB_MAX_DIGITS) { +#ifdef INVALID_NUMVAL_IS_ZERO + cob_set_exception (COB_EC_ARGUMENT_FUNCTION); + cob_alloc_set_field_uint (0); + return curr_field; +#else + /* Should this truncate or raise an exception? + What about COBOL2025 new max? */ datasize = COB_MAX_DIGITS; +#endif } - /* acquire temp buffer long enugh */ - final_buff = cob_malloc (datasize + 1U); - sign = 0; digits = 0; decimal_digits = 0; @@ -1648,8 +1654,6 @@ numval (cob_field *srcfield, cob_field *currency, const enum numval_type type) } } - cob_free (final_buff); - if (exception) { cob_set_exception (COB_EC_ARGUMENT_FUNCTION); } diff --git a/libcob/numeric.c b/libcob/numeric.c index fe1425429..36b868a3a 100644 --- a/libcob/numeric.c +++ b/libcob/numeric.c @@ -372,7 +372,7 @@ cob_decimal_clear (cob_decimal *d) void cob_decimal_set_ullint (cob_decimal *d, const cob_u64_t n) { -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG mpz_set_ui (d->value, (cob_uli_t)n); #else mpz_set_ui (d->value, (cob_uli_t)(n >> 32)); @@ -386,7 +386,7 @@ cob_decimal_set_ullint (cob_decimal *d, const cob_u64_t n) void cob_decimal_set_llint (cob_decimal *d, const cob_s64_t n) { -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG mpz_set_si (d->value, (cob_sli_t)n); #else cob_u64_t uval; @@ -455,7 +455,7 @@ cob_decimal_print (cob_decimal *d, FILE *fp) } #define MAX_LLI_DIGITS_PLUS_1 20 -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG #define MAX_LI_DIGITS_PLUS_1 20 #else #define MAX_LI_DIGITS_PLUS_1 10 @@ -497,7 +497,7 @@ const cob_uli_t cob_pow_10_uli_val[MAX_LI_DIGITS_PLUS_1] = { , 10000000 , 100000000 , 1000000000UL -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG , 10000000000 , 100000000000 , 1000000000000 @@ -701,7 +701,7 @@ cob_decimal_set_ieee64dec (cob_decimal *d, const cob_field *f) d->scale = 0; return; } -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG mpz_set_ui (d->value, data); #else mpz_set_ui (d->value, (cob_uli_t)(data >> 32)); @@ -810,7 +810,7 @@ cob_decimal_set_ieee128dec (cob_decimal *d, const cob_field *f) d->scale = 0; return; } -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG mpz_set_ui (d->value, COB_128_MSW(data)); mpz_mul_2exp (d->value, d->value, 64UL); mpz_add_ui (d->value, d->value, COB_128_LSW(data)); @@ -1187,7 +1187,7 @@ cob_decimal_set_packed (cob_decimal *d, cob_field *f) val = val * 10 + (*p >> 4); } -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG mpz_set_ui (d->value, (cob_uli_t)val); #else cob_decimal_set_ullint (d, val); @@ -1676,7 +1676,7 @@ cob_decimal_set_binary (cob_decimal *d, cob_field *f) } #endif -#elif defined(COB_LI_IS_LL) +#ifndef COB_32_BIT_LONG if (COB_FIELD_HAVE_SIGN (f)) { mpz_set_si (d->value, cob_binary_get_sint64 (f)); } else { @@ -1779,7 +1779,7 @@ cob_decimal_get_binary (cob_decimal *d, cob_field *f, const int opt) } } } -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG if (!field_sign || (overflow && !(opt & COB_STORE_TRUNC_ON_OVERFLOW))) { cob_binary_set_uint64 (f, mpz_get_ui (d->value)); } else { @@ -3707,7 +3707,7 @@ cob_cmp_llint (cob_field *f1, const cob_s64_t n) } else { if (n >= 0) return -1; } -#ifdef COB_LI_IS_LL +#ifndef COB_32_BIT_LONG mpz_set_si (cob_d2.value, (cob_sli_t)n); #else { diff --git a/libcob/screenio.c b/libcob/screenio.c index 862509f74..e0512cc19 100644 --- a/libcob/screenio.c +++ b/libcob/screenio.c @@ -843,7 +843,7 @@ adjust_attr_from_control_field (cob_flags_t *attr, cob_field *control, continue; } - /* normal attribute - apply and go on*/ + /* normal attribute - apply and go on */ if (control_attr->cobflag != 0) { if (no_indicator == 0) { *attr |= control_attr->cobflag; @@ -3300,10 +3300,10 @@ field_display (cob_field *f, cob_flags_t fattr, const int line, const int column cob_field *fgc, cob_field *bgc, cob_field *fscroll, cob_field *size_is, cob_field *control, cob_field *color) { - int sline; - int scolumn; - int size_display, fsize; - int status; + int sline; + int scolumn; + int size_display, fsize; + int status; char fig_const; /* figurative constant character */ /* LCOV_EXCL_START */ diff --git a/tests/testsuite.src/syn_misc.at b/tests/testsuite.src/syn_misc.at index 6a4107e7d..06e8f75c0 100644 --- a/tests/testsuite.src/syn_misc.at +++ b/tests/testsuite.src/syn_misc.at @@ -7559,7 +7559,7 @@ AT_DATA([prog.cob], [ AT_CAPTURE_FILE([prog.c]) AT_CHECK([COBC_GEN_DUMP_COMMENTS=1 \ - $COMPILE -C -fdump=all -w prog.cob], [0], []) + $COMPILE -C -fdump -w prog.cob], [0], []) # TODO: only execute this piece when extended $GREP works AT_CHECK([($GREP -A 200 "P_dump:" prog.c | $GREP -B 200 "END OF DUMP") || exit 77], [0], [ P_dump: