-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2089 from d70-t/open_mem_truncated_file
Don't assert if trying to open truncated file from memory.
- Loading branch information
Showing
4 changed files
with
61 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* This is part of the netCDF package. | ||
Copyright 2018 University Corporation for Atmospheric Research/Unidata | ||
See COPYRIGHT file for conditions of use. | ||
Test that netCDF provides proper error messages if broken Files are supplied. | ||
*/ | ||
|
||
#include <config.h> | ||
#include <stdio.h> | ||
#include <nc_tests.h> | ||
#include "err_macros.h" | ||
#include "netcdf.h" | ||
#include "netcdf_mem.h" | ||
|
||
#include <string.h> | ||
|
||
#define FILE_NAME "tst_broken_files.nc" | ||
#define TRUNCATED_FILE_CONTENT "\x89HDF\r\n\x1a\n" | ||
|
||
int | ||
main() { | ||
printf("\n*** Testing NetCDF-4 with truncated (broken) sample file.\n"); | ||
{ | ||
printf("*** testing via file on file-system ...\n"); | ||
FILE *fp = fopen(FILE_NAME, "w"); | ||
if(!fp) ERR; | ||
if(fwrite(TRUNCATED_FILE_CONTENT, sizeof(char), sizeof(TRUNCATED_FILE_CONTENT), fp) != sizeof(TRUNCATED_FILE_CONTENT)) ERR; | ||
fclose(fp); | ||
|
||
int ncid; | ||
if (nc_open(FILE_NAME, 0, &ncid) != NC_EHDFERR) ERR; | ||
} | ||
|
||
{ | ||
printf("*** testing via in-memory access ...\n"); | ||
int ncid; | ||
if (nc_open_mem(FILE_NAME, 0, sizeof(TRUNCATED_FILE_CONTENT), TRUNCATED_FILE_CONTENT, &ncid) != NC_EHDFERR) ERR; | ||
} | ||
SUMMARIZE_ERR; | ||
FINAL_RESULTS; | ||
} |