Skip to content

Commit

Permalink
Fix floating point exception.
Browse files Browse the repository at this point in the history
dev->max_file_size = 2 * num_recs * dev->max_block_size;

max_block_size can be 0

which gives a max_file_size which is 0

when you then calculate

write_eof = dev->max_file_size / REC_SIZE; /*compute when we add EOF*/

then write_eof = 0 and when you then do

if ((block->BlockNumber % write_eof) == 0) {

You get a nice Floating Point Execption.

We now set max_file_size to something more appropriate and assert on
write_eof being bigger then 0 so we never do a divide by zero again.

Fixes #96: btape crashes using multiple tape test when tape was written by a fill test before.
  • Loading branch information
Marco van Wieringen committed May 5, 2013
1 parent e853f43 commit e603d30
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/stored/btape.c
Expand Up @@ -1143,7 +1143,11 @@ static bool write_two_files()
* Set big max_file_size so that write_record_to_block
* doesn't insert any additional EOF marks
*/
dev->max_file_size = 2 * num_recs * dev->max_block_size;
if (dev->max_block_size) {
dev->max_file_size = 2 * num_recs * dev->max_block_size;
} else {
dev->max_file_size = 2 * num_recs * DEFAULT_BLOCK_SIZE;
}
Pmsg2(-1, _("\n=== Write, rewind, and re-read test ===\n\n"
"I'm going to write %d records and an EOF\n"
"then write %d records and an EOF, then rewind,\n"
Expand Down Expand Up @@ -2231,6 +2235,8 @@ static void fillcmd()
min_block_size = dev->min_block_size;
dev->min_block_size = dev->max_block_size;
write_eof = dev->max_file_size / REC_SIZE; /*compute when we add EOF*/
ASSERT(write_eof > 0);

set_volume_name("TestVolume1", 1);
dir_ask_sysop_to_create_appendable_volume(dcr);
dev->set_append(); /* force volume to be relabeled */
Expand Down

0 comments on commit e603d30

Please sign in to comment.