Skip to content

Commit

Permalink
Merge SVN 5018
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Nov 7, 2024
1 parent 4da60ce commit 6ea93c3
Show file tree
Hide file tree
Showing 20 changed files with 2,662 additions and 583 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

* configure.ac: replace AC_ARG_VAR by AC_SUBST where appropriate

2023-04-05 Simon Sobisch <[email protected]>

* configure.ac: pass --enable-debug to autoconf generated files as
COB_ENABLE_DEBUG, currently used for running extra test cycles in
the test suite

2023-03-03 Simon Sobisch <[email protected]>

* configure.ac: allow specification of XML2_CONFIG (only used if
Expand Down
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ Open Plans:
** several bugs in COPY REPLACING / REPLACING were fixed along with adding
support for exensions related to REPLACING LEADING / TRAILING

** for PICTURE P several fixes were made, so results may vary compared with
previous versions; sources with *leading* P never worked correct before,
and *must* be recompiled after upgrading

* Listing changes

** the timestamp in the header was changed from ANSI date format like
Expand Down Expand Up @@ -517,6 +521,11 @@ Open Plans:
that this has to take both mathematical and "C compiler portability" into
account)

** variables containing PICTURE symbol P may lead to wrong results in rare
cases (especially screenio) - please send a bug report if you catch a case;
since GC 3.2 rc3 all arithmetic operations and MOVE are believed to be
correct

** features that are known to not be portable to every environment yet
(especially when using a different compiler than GCC)
* function with variable-length RETURNING item
Expand Down
6 changes: 6 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
* typeck.c (cb_build_cond, cb_emit_divide, cb_build_move_literal):
minor refactoring

2023-04-04 Simon Sobisch <[email protected]>

* tree.c (cb_build_picture): don't include leading Ps in digit count
* typeck.c (validate_move): adjust checks for move from literal, fixing
PPP edge cases; rewrote calculation for most and least significant places

2023-03-29 Simon Sobisch <[email protected]>

* typeck.c (count_pic_edited): renamed from count_pic_alphanumeric_edited
Expand Down
3 changes: 2 additions & 1 deletion cobc/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -2566,8 +2566,9 @@ setup_parameters (struct cb_field *f)
f->pic->flag_is_calculated = 1;
break;

case CB_USAGE_COMP_5:
case CB_USAGE_COMP_N:
f->flag_real_binary = 1;
case CB_USAGE_COMP_5:
if (f->pic
&& f->pic->orig
&& f->pic->orig[0] == 'X') {
Expand Down
3 changes: 2 additions & 1 deletion cobc/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3776,8 +3776,9 @@ cb_build_picture (const char *str)
if (at_beginning) {
/* Implicit V */
v_count++;
} else {
digits += n;
}
digits += n;
if (v_count) {
scale += n;
} else {
Expand Down
153 changes: 75 additions & 78 deletions cobc/typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -11258,12 +11258,10 @@ validate_move_from_num_lit (cb_tree src, cb_tree dst, const unsigned int is_valu
{
struct cb_field *fdst = CB_FIELD_PTR (dst);
struct cb_literal *l = CB_LITERAL (src);
int most_significant = -999;
int least_significant = 999;
int leftmost_significant, most_significant, least_significant;
size_t i;
cob_s64_t val;
cb_tree loc = src->source_line ? src : dst;
unsigned char *p;

/* Numeric literal */
if (l->all) {
Expand All @@ -11274,24 +11272,32 @@ validate_move_from_num_lit (cb_tree src, cb_tree dst, const unsigned int is_valu
return MOVE_OK;
}

/* Compute the most significant figure place */
for (i = 0; i < l->size; i++) {
if (l->data[i] != '0') {
/* Compute the most significant figure place
in relatation to the decimal point (negative = decimal position) */
for (leftmost_significant = 0; leftmost_significant < l->size; leftmost_significant++) {
if (l->data[leftmost_significant] != '0') {
break;
}
}
if (i != l->size) {
most_significant = (int) (l->size - l->scale - i - 1);
if (leftmost_significant == l->size) {
most_significant = -999;
} else {
most_significant = l->size - l->scale - leftmost_significant;
if (most_significant < 1) most_significant--;
}

/* Compute the least significant figure place */
for (i = 0; i < l->size; i++) {
if (l->data[l->size - i - 1] != '0') {
/* Compute the least significant figure place
in relatation to the decimal point (negative = decimal position) */
for (i = l->size - 1; i != 0; i--) {
if (l->data[i] != '0') {
break;
}
}
if (i != l->size) {
least_significant = (int)i - l->scale;
if (i == 0) {
least_significant = 999;
} else {
least_significant = (l->size - l->scale) - i;
if (least_significant < 1) least_significant--;
}

/* Value check */
Expand Down Expand Up @@ -11323,18 +11329,23 @@ validate_move_from_num_lit (cb_tree src, cb_tree dst, const unsigned int is_valu
}
/* Fall-through */
case CB_CATEGORY_NUMERIC:
if (fdst->pic->scale < 0) {
{
const struct cb_picture *pic = fdst->pic;
if (pic->scale < 0) {
/* Check for PIC 9(n)P(m) */
if (least_significant < -fdst->pic->scale) {
if (least_significant <= -pic->scale) {
/* 12300 (3) <= 99PPP (- -3) */
return MOVE_VALUE_NOT_FIT_PIC;
}
} else if (fdst->pic->scale > fdst->pic->size) {
} else if (pic->scale > pic->digits) {
/* Check for PIC P(n)9(m) */
if (most_significant >= fdst->pic->size - fdst->pic->scale) {
if (most_significant > pic->digits - pic->scale - 1) {
/* .00123 (-3) > PPP99 (-4 [2 - 5 - 1]) */
return MOVE_VALUE_NOT_FIT_PIC;
}
}
break;
}
case CB_CATEGORY_ALPHABETIC:
if (is_value) {
return MOVE_ALNUM_EXPECTED;
Expand Down Expand Up @@ -11365,128 +11376,111 @@ validate_move_from_num_lit (cb_tree src, cb_tree dst, const unsigned int is_valu
/* Size check */
if (fdst->flag_real_binary
|| ( !cb_binary_truncate
&& fdst->pic->scale == 0
&& fdst->pic->scale <= 0
&& ( fdst->usage == CB_USAGE_COMP_5
|| fdst->usage == CB_USAGE_COMP_X
|| fdst->usage == CB_USAGE_COMP_N
|| fdst->usage == CB_USAGE_BINARY))) {
p = l->data;
for (i = 0; i < l->size; i++) {
if (l->data[i] != '0') {
p = &l->data[i];
break;

i = l->size - leftmost_significant;
if (i <= 19) {
val = cb_get_long_long (src);
} else if (fdst->size < 8) {
return MOVE_NUMERIC_LIT_OVERFLOW;
} else {
val = 0;
}
/* handle negative scale aka 999PPP */
if (fdst->pic->scale < 0) {
int j = fdst->pic->scale;
i += j;
while (j != 0) {
val /= 10;
j++;
}
}
i = l->size - i;

switch (fdst->size) {
case 1:
if (i > cb_max_binary) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
val = cb_get_long_long (src);
if (fdst->pic->have_sign) {
if (val < COB_S64_C(-128)
|| val > COB_S64_C(127)) {
if (val < COB_S64_C (-128)
|| val > COB_S64_C (127)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
} else {
if (val > COB_S64_C(255)) {
if (val > COB_S64_C (255)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
}
break;
case 2:
if (i > cb_max_binary) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
val = cb_get_long_long (src);
if (fdst->pic->have_sign) {
if (val < COB_S64_C(-32768) ||
val > COB_S64_C(32767)) {
if (val < COB_S64_C (-32768) ||
val > COB_S64_C (32767)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
} else {
if (val > COB_S64_C(65535)) {
if (val > COB_S64_C (65535)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
}
break;
case 3:
if (i > cb_max_binary) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
val = cb_get_long_long (src);
if (fdst->pic->have_sign) {
if (val < COB_S64_C(-8388608)
|| val > COB_S64_C(8388607)) {
if (val < COB_S64_C (-8388608)
|| val > COB_S64_C (8388607)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
} else {
if (val > COB_S64_C(16777215)) {
if (val > COB_S64_C (16777215)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
}
break;
case 4:
if (i > cb_max_binary) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
val = cb_get_long_long (src);
if (fdst->pic->have_sign) {
if (val < COB_S64_C(-2147483648)
|| val > COB_S64_C(2147483647)) {
if (val < COB_S64_C (-2147483648)
|| val > COB_S64_C (2147483647)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
} else {
if (val > COB_S64_C(4294967295)) {
if (val > COB_S64_C (4294967295)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
}
break;
case 5:
if (i > cb_max_binary) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
val = cb_get_long_long (src);
if (fdst->pic->have_sign) {
if (val < COB_S64_C(-549755813888)
|| val > COB_S64_C(549755813887)) {
if (val < COB_S64_C (-549755813888)
|| val > COB_S64_C (549755813887)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
} else {
if (val > COB_S64_C(1099511627775)) {
if (val > COB_S64_C (1099511627775)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
}
break;
case 6:
if (i > cb_max_binary) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
val = cb_get_long_long (src);
if (fdst->pic->have_sign) {
if (val < COB_S64_C(-140737488355328)
|| val > COB_S64_C(140737488355327)) {
if (val < COB_S64_C (-140737488355328)
|| val > COB_S64_C (140737488355327)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
} else {
if (val > COB_S64_C(281474976710655)) {
if (val > COB_S64_C (281474976710655)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
}
break;
case 7:
if (i > cb_max_binary) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
val = cb_get_long_long (src);
if (fdst->pic->have_sign) {
if (val < COB_S64_C(-36028797018963968)
|| val > COB_S64_C(36028797018963967)) {
if (val < COB_S64_C (-36028797018963968)
|| val > COB_S64_C (36028797018963967)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
} else {
if (val > COB_S64_C(72057594037927935)) {
if (val > COB_S64_C (72057594037927935)) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
}
Expand All @@ -11500,9 +11494,10 @@ validate_move_from_num_lit (cb_tree src, cb_tree dst, const unsigned int is_valu
return MOVE_NUMERIC_LIT_OVERFLOW;
}
if (i == 19
&& memcmp (p, l->sign ? "9223372036854775808" :
"9223372036854775807",
(size_t)19) > 0) {
&& memcmp (l->data + leftmost_significant,
l->sign ? "9223372036854775808" :
"9223372036854775807",
19) > 0) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
} else {
Expand All @@ -11513,7 +11508,9 @@ validate_move_from_num_lit (cb_tree src, cb_tree dst, const unsigned int is_valu
return MOVE_NUMERIC_LIT_OVERFLOW;
}
if (i == 20
&& memcmp (p, "18446744073709551615", (size_t)20) > 0) {
&& memcmp (l->data + leftmost_significant,
"18446744073709551615",
20) > 0) {
return MOVE_NUMERIC_LIT_OVERFLOW;
}
}
Expand All @@ -11530,7 +11527,7 @@ validate_move_from_num_lit (cb_tree src, cb_tree dst, const unsigned int is_valu
} else {
*size = fdst->pic->digits;
}
if (most_significant >= *size) {
if (most_significant > *size) {
*size = -1;
return MOVE_GENERAL_OVERFLOW;
}
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2703,6 +2703,7 @@ AC_SUBST([COB_OBJECT_EXT])
AC_SUBST([COB_MODULE_EXT])
AC_SUBST([COB_EXE_EXT])
AC_SUBST([LIBCOB_VER])
AC_SUBST([COB_ENABLE_DEBUG], [$enable_debug]) # needed for tests/atlocal
dnl was used in bin/Makefile.am - seems not to be needed
dnl AC_SUBST([COB_EXPORT_DYN])
Expand Down
Loading

0 comments on commit 6ea93c3

Please sign in to comment.