Skip to content

Commit ef01dee

Browse files
daviesrobwhitwham
authored andcommitted
Fix inadvertent variable length array
The C standard says that for an array to not be a variable length type, it's size must be a constant integer expression. A const variable does not satisfy the definition of a constant integer expression, but compliers may accept them as an extension. We used to get away with this, but the compiler shipped with MacOS Tahoe is more strict and prints a warning. Fix by changing the const variable to a macro. See https://stackoverflow.com/questions/72716896/ for more details.
1 parent 28a0c87 commit ef01dee

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

vcfconcat.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@ static void naive_concat(args_t *args)
892892
int nskip;
893893
if ( type.format==bcf )
894894
{
895-
const size_t magic_len = 5 + 4; // "Magic" string + header length
895+
// Macro here as magic_len is used in an array declaration.
896+
#define magic_len (5 + 4) // "Magic" string + header length.
896897
uint8_t magic[magic_len];
897898
if ( bgzf_read(fp, magic, magic_len) != magic_len ) error("\nFailed to read the BCF header in %s\n", args->fnames[i]);
898899
// First five bytes are the "Magic" string
@@ -905,10 +906,11 @@ static void naive_concat(args_t *args)
905906
// write only the first header
906907
if ( i==0 )
907908
{
908-
if ( bgzf_write(bgzf_out, magic, magic_len) != magic_len ) error("\nFailed to write %zu bytes to %s\n", magic_len,args->output_fname);
909+
if ( bgzf_write(bgzf_out, magic, magic_len) != magic_len ) error("\nFailed to write %d bytes to %s\n", magic_len,args->output_fname);
909910
if ( bgzf_write(bgzf_out, tmp.s, tmp.l) != tmp.l) error("\nFailed to write %"PRId64" bytes to %s\n", (uint64_t)tmp.l,args->output_fname);
910911
}
911912
nskip = fp->block_offset;
913+
#undef magic_len
912914
}
913915
else
914916
{

0 commit comments

Comments
 (0)