diff options
author | Jeff McGlynn <jwmcglynn@google.com> | 2018-08-16 16:53:26 -0700 |
---|---|---|
committer | Jeff McGlynn <jwmcglynn@google.com> | 2018-08-16 18:13:43 -0700 |
commit | 16661ba8c0103c2571e84a59a107c9e41dbe60dc (patch) | |
tree | 954429f1e6f9f558f62bcc541f7db8a9b1e38f45 /src/base | |
parent | 06beed61ea806970a8c6023daf20436c2e65f25d (diff) |
Fix ASAN failures in integer_sequence_codec and partition
Introduce UTILS_RELEASE_ASSERT, which crashes if the condition isn't
met, even on release builds.
Update integer_sequence_codec and partition to use the new tests to
validate input parameters, and update the tests so that they expect the
crash to occur even on release builds.
Bug: 112691516, 112669735
Change-Id: Ic82edeffc64ca0f2b0d17f1c63563dfd8d9cdd71
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/BUILD.bazel | 1 | ||||
-rw-r--r-- | src/base/utils.h | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/base/BUILD.bazel b/src/base/BUILD.bazel index 9d8b9a0..09f723d 100644 --- a/src/base/BUILD.bazel +++ b/src/base/BUILD.bazel @@ -22,6 +22,7 @@ cc_library( "string_utils.h", "type_traits.h", "uint128.h", + "utils.h", ], visibility = ["//src/decoder:__pkg__"], ) diff --git a/src/base/utils.h b/src/base/utils.h new file mode 100644 index 0000000..0a4fabd --- /dev/null +++ b/src/base/utils.h @@ -0,0 +1,35 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ASTC_CODEC_BASE_UTILS_H_ +#define ASTC_CODEC_BASE_UTILS_H_ + +#include <cassert> +#include <cstdio> +#include <cstdlib> + +#ifdef NDEBUG +#define UTILS_RELEASE_ASSERT(x) \ + do { \ + const bool result = (x); \ + if (!result) { \ + fprintf(stderr, "Error: UTILS_RELEASE_ASSERT failed: %s\n", #x); \ + abort(); \ + } \ + } while (false) +#else +#define UTILS_RELEASE_ASSERT(x) assert(x) +#endif + +#endif // ASTC_CODEC_BASE_UTILS_H_ |