Verify valid compression level ranges

This commit is contained in:
Richard Berger
2020-08-26 16:03:18 -04:00
parent e0439ac94f
commit 046fd3d14b
2 changed files with 9 additions and 4 deletions

View File

@ -27,7 +27,7 @@ DumpAtomGZ::DumpAtomGZ(LAMMPS *lmp, int narg, char **arg) :
{
gzFp = NULL;
compression_level = 9;
compression_level = Z_BEST_COMPRESSION;
if (!compressed)
error->all(FLERR,"Dump atom/gz only writes compressed files");
@ -171,8 +171,10 @@ int DumpAtomGZ::modify_param(int narg, char **arg)
if(consumed == 0) {
if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
compression_level = force->inumeric(FLERR,arg[1]);
if (compression_level <= 0) error->all(FLERR,"Illegal dump_modify command");
int min_level = Z_DEFAULT_COMPRESSION;
int max_level = Z_BEST_COMPRESSION;
if (compression_level < 0 || compression_level > max_level)
error->all(FLERR, fmt::format("Illegal dump_modify command: compression level must in the range of [{}, {}]", min_level, max_level));
return 2;
}
}