Skip to content

param_cnt: reject invalid inputs instead of crashing or reporting false success - #66

Merged
lenzo-ka merged 1 commit into
masterfrom
kal-param-cnt-fix
Aug 16, 2026
Merged

param_cnt: reject invalid inputs instead of crashing or reporting false success#66
lenzo-ka merged 1 commit into
masterfrom
kal-param-cnt-fix

Conversation

@lenzo-ka

Copy link
Copy Markdown
Contributor

Fixes #65.

param_cnt turned several invalid-input conditions into either a crash or a
successful exit. This makes each one an ordinary, named initialization failure,
and defers creating the output file until a nonzero count exists.

What changes

  • -segdir is required only where it is used. State and codebook counting
    need segmentations; phone counting does not. A missing -segdir is now a
    named error for state/cb and is accepted for phone, instead of passing a
    null value into corpus_set_seg_dir().
  • The control file is checked. corpus_set_ctl_filename()'s result is no
    longer discarded; an unusable -ctlfn fails initialization.
  • cb counting requires -ts2cbfn. Without it, mdef->cb is never
    populated and cb_cnt() would index a null map. Counting now refuses to start.
  • Unknown -paramtype is rejected instead of scanning the corpus with an
    unset counting-function pointer.
  • Zero counted utterances is a failure. enum_corpus() now returns the
    number of utterances that reached the counting callback (and skips an indented
    first-line comment that lineiter_start_clean() can otherwise expose as a
    control entry). A control that yields no counted utterance — empty,
    whitespace-only, or comment-only — fails instead of producing an all-zero file.
  • -outputfn is opened only after enumeration produced nonzero work, so a
    failed run never leaves an empty or all-zero count file behind. A failed
    fopen() is now a nonzero exit rather than a silent write to a null stream.

Verification

param_cnt builds cleanly (no new warnings). param_cnt -paramtype state
without -segdir now prints You must specify a segmentation directory using -segdir and exits 1; -paramtype phone no longer requires -segdir. The
counting core matches the implementation carried and tested downstream, whose
boundary suite covers empty / whitespace-only / indented-comment-only controls,
a directory / unreadable file / /dev/null control, a malformed later control
line, unknown type, missing codebook mapping, output-open failure, and
successful phone counting without -segdir.

Out of scope: the cmd_ln_parse() return-contract issue (#63) and the separate
pre-existing -sentdir dereference reachable when -lsnfn is absent.

…se success

Turn several param_cnt failure modes into named initialization errors:

- Require -segdir only for state and cb counting; phone counting does
  not need segmentations, so a missing -segdir is required where it is
  actually used and no longer forced everywhere.
- Check corpus_set_ctl_filename() and fail on an unusable control file.
- Require -ts2cbfn for cb counting so cb_cnt never indexes a null
  state-to-codebook map.
- Reject an unknown -paramtype instead of scanning with an unset
  counting function pointer.
- Have enum_corpus() report the number of utterances that reached the
  counting callback (skipping an indented first-line comment), and
  reject a zero count before any output is written.
- Open -outputfn only after enumeration produced nonzero work, so a
  failed run never leaves an empty or all-zero count file behind.

Fixes #65.
@lenzo-ka
lenzo-ka marked this pull request as ready for review August 16, 2026 23:07
@lenzo-ka
lenzo-ka merged commit e273816 into master Aug 16, 2026
8 checks passed
@lenzo-ka
lenzo-ka deleted the kal-param-cnt-fix branch August 17, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

param_cnt accepts invalid inputs and can emit empty counts as success

1 participant