Files
gcc/libgcobol/valconv.h
Robert Dubner 54e4f75b7d cobol: Eliminate cppcheck warnings for libgcobol [PR119323]
I configured and ran cppcheck-2.17.0 with this config file:

<?xml version="1.0"?>
<def format="2">
  <define name="HOST_SIZE_T_PRINT_UNSIGNED" value="&quot;%ld&quot;"/>
  <define name="GCC_PRISZ" value="&quot;z&quot;"/>
  <define name="YYLTYPE" value="struct {int first_line; int first_column; int last_line; int last_column;}"/>
  <define name="__FLT128_MANT_DIG__" value="113"/>
  <define name="__FLT128_MIN_EXP__" value="-16381"/>
</def>

and this command line

cppcheck --inline-suppr --enable=all --force --language=c++ --library=$CFG \
--check-level=exhaustive \
--disable=unusedFunction \
--disable=missingInclude \
$(cat $FILES) > $RESULT 2>&1

$FILES was all of the .cc files in libgcobol.

The result was many hundreds of warnings.  The vast bulk of them were
recommendations for declaring variables as const, recommendations for
changing C-style casts to C++ casts, cheery notes about shadowed
variables, and complaints that malloc() results weren't being checked
for errors.

Two and a half days of applied OCD on my part has reduced the number of
warnings down to zero.

libgcobol/ChangeLog:

	PR cobol/119323
	* charmaps.cc (__gg__raw_to_ascii):  Eliminate cppcheck warnings.
	(__gg__raw_to_ebcdic): Likewise.
	(__gg__ebcdic_to_console): Likewise.
	(__gg__console_to_ascii): Likewise.
	(__gg__console_to_ebcdic): Likewise.
	* common-defs.h (struct cbl_declarative_t): Likewise.
	* gfileio.cc (get_filename): Likewise.
	(max_value): Likewise.
	(relative_file_delete_varying): Likewise.
	(relative_file_delete): Likewise.
	(read_an_indexed_record): Likewise.
	(position_state_restore): Likewise.
	(indexed_file_delete): Likewise.
	(indexed_file_start): Likewise.
	(sequential_file_rewrite): Likewise.
	(relative_file_write_varying): Likewise.
	(relative_file_write): Likewise.
	(sequential_file_write): Likewise.
	(indexed_file_write): Likewise.
	(__io__file_write): Likewise.
	(line_sequential_file_read): Likewise.
	(indexed_file_read): Likewise.
	(file_indexed_open): Likewise.
	(__gg__file_reopen): Likewise.
	* gmath.cc (conditional_stash): Likewise.
	(__gg__pow): Likewise.
	(multiply_int256_by_int64): Likewise.
	(add_int256_to_int256): Likewise.
	(divide_int256_by_int64): Likewise.
	(squeeze_int256): Likewise.
	(get_int256_from_qualified_field): Likewise.
	(__gg__add_fixed_phase1): Likewise.
	(__gg__addf1_fixed_phase2): Likewise.
	(__gg__fixed_phase2_assign_to_c): Likewise.
	(__gg__add_float_phase1): Likewise.
	(__gg__addf1_float_phase2): Likewise.
	(__gg__float_phase2_assign_to_c): Likewise.
	(__gg__addf3): Likewise.
	(__gg__subtractf1_fixed_phase2): Likewise.
	(__gg__subtractf2_fixed_phase1): Likewise.
	(__gg__subtractf1_float_phase2): Likewise.
	(__gg__subtractf2_float_phase1): Likewise.
	(__gg__subtractf3): Likewise.
	(__gg__multiplyf1_phase1): Likewise.
	(multiply_int128_by_int128): Likewise.
	(__gg__multiplyf1_phase2): Likewise.
	(__gg__multiplyf2): Likewise.
	(shift_in_place128): Likewise.
	(divide_int128_by_int128): Likewise.
	(__gg__dividef1_phase2): Likewise.
	(__gg__dividef23): Likewise.
	(__gg__dividef45): Likewise.
	* intrinsic.cc (struct input_state): Likewise.
	(get_value_as_double_from_qualified_field): Likewise.
	(kahan_summation): Likewise.
	(variance): Likewise.
	(get_all_time): Likewise.
	(populate_ctm_from_date): Likewise.
	(populate_ctm_from_time): Likewise.
	(ftime_replace): Likewise.
	(__gg__abs): Likewise.
	(__gg__acos): Likewise.
	(__gg__annuity): Likewise.
	(__gg__asin): Likewise.
	(__gg__atan): Likewise.
	(__gg__byte_length): Likewise.
	(__gg__char): Likewise.
	(__gg__combined_datetime): Likewise.
	(__gg__cos): Likewise.
	(__gg__date_of_integer): Likewise.
	(__gg__date_to_yyyymmdd): Likewise.
	(__gg__day_of_integer): Likewise.
	(__gg__day_to_yyyyddd): Likewise.
	(__gg__exp): Likewise.
	(__gg__exp10): Likewise.
	(__gg__factorial): Likewise.
	(__gg__formatted_current_date): Likewise.
	(__gg__formatted_date): Likewise.
	(__gg__formatted_datetime): Likewise.
	(__gg__formatted_time): Likewise.
	(__gg__integer): Likewise.
	(__gg__integer_of_date): Likewise.
	(__gg__integer_of_day): Likewise.
	(__gg__integer_part): Likewise.
	(__gg__fraction_part): Likewise.
	(__gg__log): Likewise.
	(__gg__log10): Likewise.
	(__gg__max): Likewise.
	(__gg__lower_case): Likewise.
	(__gg__median): Likewise.
	(__gg__min): Likewise.
	(numval): Likewise.
	(numval_c): Likewise.
	(__gg__numval): Likewise.
	(__gg__test_numval): Likewise.
	(__gg__numval_c): Likewise.
	(__gg__test_numval_c): Likewise.
	(__gg__ord): Likewise.
	(__gg__rem): Likewise.
	(__gg__trim): Likewise.
	(__gg__random): Likewise.
	(__gg__reverse): Likewise.
	(__gg__sign): Likewise.
	(__gg__sin): Likewise.
	(__gg__sqrt): Likewise.
	(__gg__tan): Likewise.
	(__gg__test_date_yyyymmdd): Likewise.
	(__gg__test_day_yyyyddd): Likewise.
	(__gg__upper_case): Likewise.
	(__gg__year_to_yyyy): Likewise.
	(gets_int): Likewise.
	(gets_year): Likewise.
	(gets_month): Likewise.
	(gets_day): Likewise.
	(gets_day_of_week): Likewise.
	(gets_day_of_year): Likewise.
	(gets_week): Likewise.
	(gets_hours): Likewise.
	(gets_minutes): Likewise.
	(gets_seconds): Likewise.
	(gets_nanoseconds): Likewise.
	(fill_cobol_tm): Likewise.
	(__gg__test_formatted_datetime): Likewise.
	(__gg__integer_of_formatted_date): Likewise.
	(__gg__seconds_from_formatted_time): Likewise.
	(__gg__hex_of): Likewise.
	(__gg__highest_algebraic): Likewise.
	(__gg__lowest_algebraic): Likewise.
	(floating_format_tester): Likewise.
	(__gg__numval_f): Likewise.
	(__gg__test_numval_f): Likewise.
	(ismatch): Likewise.
	(iscasematch): Likewise.
	(strstr): Likewise.
	(strcasestr): Likewise.
	(strlaststr): Likewise.
	(strcaselaststr): Likewise.
	(__gg__substitute): Likewise.
	(__gg__locale_compare): Likewise.
	(__gg__locale_date): Likewise.
	(__gg__locale_time): Likewise.
	(__gg__locale_time_from_seconds): Likewise.
	* libgcobol.cc (class ec_status_t): Likewise.
	(__gg__set_truncation_mode): Likewise.
	(malloc): Likewise.
	(__gg__mabort): Likewise.
	(__gg__resize_int_p): Likewise.
	(__gg__resize_treeplet): Likewise.
	(var_is_refmod): Likewise.
	(value_is_too_big): Likewise.
	(__gg__string_to_alpha_edited_ascii): Likewise.
	(int128_to_field): Likewise.
	(edited_to_binary): Likewise.
	(get_binary_value_local): Likewise.
	(__gg__get_date_yymmdd): Likewise.
	(__gg__get_date_yyyymmdd): Likewise.
	(__gg__get_date_yyddd): Likewise.
	(__gg__get_yyyyddd): Likewise.
	(__gg__get_date_dow): Likewise.
	(get_scaled_rdigits): Likewise.
	(format_for_display_internal): Likewise.
	(compare_88): Likewise.
	(get_float128): Likewise.
	(compare_field_class): Likewise.
	(compare_strings): Likewise.
	(__gg__compare_2): Likewise.
	(__gg__sort_table): Likewise.
	(init_var_both): Likewise.
	(alpha_to_alpha_move_from_location): Likewise.
	(alpha_to_alpha_move): Likewise.
	(__gg__move): Likewise.
	(__gg__move_literala): Likewise.
	(__gg__sort_workfile): Likewise.
	(__gg__merge_files): Likewise.
	(normalize_id): Likewise.
	(inspect_backward_format_1): Likewise.
	(__gg__inspect_format_1): Likewise.
	(inspect_backward_format_2): Likewise.
	(__gg__inspect_format_2): Likewise.
	(__gg__inspect_format_4): Likewise.
	(move_string): Likewise.
	(__gg__string): Likewise.
	(display_both): Likewise.
	(__gg__display_string): Likewise.
	(__gg__accept): Likewise.
	(__gg__binary_value_from_qualified_field): Likewise.
	(__gg__float128_from_qualified_field): Likewise.
	(float128_to_int128): Likewise.
	(float128_to_location): Likewise.
	(__gg__set_initial_switch_value): Likewise.
	(is_numeric_display_numeric): Likewise.
	(is_packed_numeric): Likewise.
	(is_alpha_a_number): Likewise.
	(__gg__classify): Likewise.
	(__gg__accept_envar): Likewise.
	(__gg__set_envar): Likewise.
	(command_line_plan_b): Likewise.
	(__gg__get_command_line): Likewise.
	(__gg__set_pointer): Likewise.
	(__gg__ascii_to_internal_field): Likewise.
	(__gg__internal_to_console_in_place): Likewise.
	(__gg__routine_to_call): Likewise.
	(__gg__fetch_call_by_value_value): Likewise.
	(__gg__assign_value_from_stack): Likewise.
	(__gg__literaln_alpha_compare): Likewise.
	(string_in): Likewise.
	(__gg__unstring): Likewise.
	(local_ec_type_of): Likewise.
	(struct exception_descr_t): Likewise.
	(struct cbl_exception_t): Likewise.
	(cbl_enabled_exception_t: Likewise.: Likewise.dump): Likewise.
	(__gg__match_exception): Likewise.
	(__gg__float128_from_location): Likewise.
	(__gg__integer_from_float128): Likewise.
	(__gg__set_exception_file): Likewise.
	(__gg__func_exception_file): Likewise.
	(__gg__set_exception_code): Likewise.
	(__gg__is_float_infinite): Likewise.
	(__gg__float32_from_128): Likewise.
	(__gg__float32_from_64): Likewise.
	(__gg__float64_from_128): Likewise.
	(__gg__copy_as_big_endian): Likewise.
	(__gg__get_figconst_data): Likewise.
	(find_in_dirs): Likewise.
	(__gg__function_handle_from_cobpath): Likewise.
	(__gg__just_mangle_name): Likewise.
	(__gg__function_handle_from_literal): Likewise.
	(__gg__function_handle_from_name): Likewise.
	(__gg__mirror_range): Likewise.
	(__gg__deallocate): Likewise.
	(__gg__allocate): Likewise.
	(__gg__module_name): Likewise.
	(__gg__set_env_name): Likewise.
	(__gg__set_env_value): Likewise.
	* libgcobol.h (__gg__mabort): Likewise.
	(massert): Likewise.
	(PTRCAST): Likewise.
	(__gg__float128_from_location): Likewise.
	(__gg__set_exception_file): Likewise.
	(__gg__binary_value_from_qualified_field): Likewise.
	(__gg__float128_from_qualified_field): Likewise.
	* valconv.cc (__gg__realloc_if_necessary): Likewise.
	(__gg__alphabet_create): Likewise.
	(__gg__string_to_numeric_edited): Likewise.
	(__gg__string_to_alpha_edited): Likewise.
	* valconv.h: Likewise.
2025-06-04 11:31:51 -04:00

81 lines
3.5 KiB
C++

/*
* Copyright (c) 2021-2025 Symas Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of the Symas Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __VALCONV_H
#define __VALCONV_H
extern int __gg__decimal_point ;
extern int __gg__decimal_separator ;
extern int __gg__quote_character ;
extern int __gg__low_value_character ;
extern int __gg__high_value_character ;
extern char **__gg__currency_signs ;
extern int __gg__default_currency_sign;
extern char *__gg__ct_currency_signs[256]; // Compile-time currency signs
// All "ordinals" are zero-based ordinals. The COBOL spec's ordinal values
// for ordinary ASCII/EBCDIC ranger from 1 to 256, so we call them zero through
// 255. We use unsigned ints so that when an custom alphabet is described, we
// can make every unmentioned character have an ordinal greater than the final
// ordinal of the custom list.
struct alphabet_state
{
unsigned short collation[256];
unsigned char low_char;
unsigned char high_char;
};
extern std::unordered_map<size_t, alphabet_state> __gg__alphabet_states;
extern "C"
{
void __gg__realloc_if_necessary(char **dest, size_t *dest_size, size_t new_size);
void __gg__alphabet_create(cbl_encoding_t encoding,
size_t alphabet_index,
const unsigned char *alphabet,
int low_char,
int high_char );
bool __gg__string_to_numeric_edited(char * const dest,
const char *source, // ASCII
int rdigits,
int is_negative,
const char *picture);
void __gg__string_to_alpha_edited(char *dest,
const char *source,
int slength,
const char *picture);
void __gg__currency_sign_init();
void __gg__currency_sign(int symbol, const char *sign);
void __gg__remove_trailing_zeroes(char *p);
}
#endif