Skip to content

Add extra bgzip error checking - #2059

Merged
jkbonfield merged 1 commit into
samtools:developfrom
daviesrob:bgzip-error-checks
Aug 6, 2026
Merged

Add extra bgzip error checking#2059
jkbonfield merged 1 commit into
samtools:developfrom
daviesrob:bgzip-error-checks

Conversation

@daviesrob

Copy link
Copy Markdown
Member

Add more error checking to the bgzip application, mostly for memory allocations, but it will also more directly report read failures (previously these relied on hclose() returning an error after a read failure). For brevity, reporting is done using the existing error() function, which is now also annotated with HTS_NORETURN.

Changes an instance of strcpy()/strcat() to the less controversial snprintf().

So far I've resisted splitting the rather large main() function up, but it is quite tempting.

@jkbonfield jkbonfield left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks fine bar a missing newline.

Comment thread bgzip.c Outdated
size_t len = strlen(argv[optind]);
char *name = hts_malloc_ps(sizeof(*name), len, 5);
if (!name)
error("[bgzip] Couldn't allocate space for output file name");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error() requires a newline, unlike hts_log_error. Maybe it should be changed, but easier to to fix it here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline should now be present.

Add more error checking to the bgzip application, mostly for
memory allocations, but it will also more directly report
read failures (previously these relied on hclose() returning
an error after a read failure).  For brevity, reporting is done
using the existing error() function, which is now also annotated
with HTS_NORETURN.

Changes an instance of strcpy()/strcat() to the less controversial
snprintf().

Signed-off-by: Rob Davies <rmd+git@sanger.ac.uk>
@daviesrob
daviesrob force-pushed the bgzip-error-checks branch from ddca391 to 77f0036 Compare July 30, 2026 15:56
@jkbonfield
jkbonfield merged commit e5f2f29 into samtools:develop Aug 6, 2026
19 of 20 checks passed
@daviesrob
daviesrob deleted the bgzip-error-checks branch August 6, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants