[Ada] Avoid uninitialized variable in bounded containers

Programming / Compilers / GCC - pmderodat [138bc75d-0d04-0410-961f-82ee72b054a4] - 18 September 2019 08:31 EDT

In function Copy in Ada.Containers.Bounded_Ordered_Sets and other bounded containers packages, remove a possible use of an uninitialized
variable. This was not a bug, because the uninitialized variable could be used only if checks are suppressed, and the checks would have failed, leading to erroneous execution.

However, it seems more robust this way, and is probably equally efficient, and avoids a warning that is given if checks are suppressed, and the -Wall switch is given, and optimization is turned on.

2019-09-18 Bob Duff

gcc/ada/

- libgnat/a-cbhama.adb, libgnat/a-cbhase.adb, libgnat/a-cbmutr.adb, libgnat/a-cborma.adb, libgnat/a-cborse.adb, libgnat/a-cobove.adb (Copy): Avoid reading the uninitialized variable C in the Checks = False case. Change
variable to be a constant.

gcc/testsuite/

- gnat.dg/containers1.adb, gnat.dg/containers1.ads: New testcase.

10789c9ab70 [Ada] Avoid uninitialized variable in bounded containers
gcc/ada/ChangeLog | 8 ++++++++
gcc/ada/libgnat/a-cbhama.adb | 14 +++++---------
gcc/ada/libgnat/a-cbhase.adb | 12 +++++-------
gcc/ada/libgnat/a-cbmutr.adb | 13 +++++--------
gcc/ada/libgnat/a-cborma.adb | 15 +++++----------
gcc/ada/libgnat/a-cborse.adb | 13 +++++--------
gcc/ada/libgnat/a-cobove.adb | 16 +++++-----------
gcc/testsuite/ChangeLog | 5 +++++
gcc/testsuite/gnat.dg/containers1.adb | 5 +++++
gcc/testsuite/gnat.dg/containers1.ads | 6 ++++++
10 files changed, 54 insertions(+), 53 deletions(-)

Upstream: gcc.gnu.org


  • Share