HDFGroup / HDFGroup/hdf5

H5C__image_stats() uses FUNC_ENTER_NOAPI instead of FUNC_ENTER_PACKAGE, fails its own naming-convention assert

Open Beginner friendly
#6,667 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
988
Forks
355
Avg merge
4d 2h
Merged PRs (30d)
12

Description

## Description

`H5C__image_stats()` in `src/H5Cdbg.c` (currently line 1558 on `develop`, commit 7f1e49206d9) is a double-underscore "package-private" function, but it enters with `FUNC_ENTER_NOAPI(FAIL)` instead of `FUNC_ENTER_PACKAGE`:

```c
herr_t
#if H5C_COLLECT_CACHE_STATS
H5C__image_stats(H5C_t *cache_ptr, bool print_header)
#else /* H5C_COLLECT_CACHE_STATS */
H5C__image_stats(H5C_t *cache_ptr, bool H5_ATTR_UNUSED print_header)
#endif /* H5C_COLLECT_CACHE_STATS */
{
...
FUNC_ENTER_NOAPI(FAIL)
```

`FUNC_ENTER_NOAPI` checks the function name against `H5_IS_PRIVATE()` (single-underscore convention, e.g. `H5X_foo`), while `FUNC_ENTER_PACKAGE` checks against `H5_IS_PKG()` (double-underscore convention, e.g. `H5X__foo`). Since `H5C__image_stats` uses the double-underscore convention, `H5_IS_PRIVATE(__func__)` evaluates false, and in any debug build (`NDEBUG` not defined) the very first call to this function aborts the process:

```
Assertion `...' failed.
"Function naming conventions are incorrect (see H5private.h)"
"(this is usually due to an incorrect number of underscores in the function name)"
```

We hit this via `assert()` failure while exercising code paths that call `H5C__image_stats()` with `H5C_COLLECT_CACHE_STATS` enabled in a debug build.

## Fix

Change `FUNC_ENTER_NOAPI(FAIL)` to `FUNC_ENTER_PACKAGE` on that line. This is a safe drop-in replacement — both macros have identical structure (same error-handling setup, same package-init gating via `H5_LIKELY(H5_PKG_INIT_VAR || !H5_TERM_GLOBAL)`), differing only in which naming-convention predicate they assert.

We found and fixed the identical class of bug (wrong `FUNC_ENTER_*` variant for a double-underscore name) in several other functions while working on a separate branch; `H5C__image_stats` is the one remaining instance we found via a full-tree scan that isn't part of that branch's own changes, so filing it separately here against `develop`.

## Reproduction

Any debug build with `H5C_COLLECT_CACHE_STATS` defined, calling `H5C__image_stats()` (e.g. via the cache-image statistics path), will abort on first call.

## Environment

- `develop` branch, commit `7f1e49206d9` (current HEAD `44426bfc7d5` at time of filing)
- Linux, Debug build, `NDEBUG` not defined

Contributor guide

Open the contributing guide

Research direction

Open src/H5Cdbg.c and inspect H5C__image_stats() around line 1558, then compare the FUNC_ENTER_NOAPI and FUNC_ENTER_PACKAGE checks described in the issue. Build a Debug configuration with H5C_COLLECT_CACHE_STATS enabled and exercise the cache-image statistics path; done means the naming-convention assertion no longer aborts the first call.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
databases
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
92/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.