Skip to content

Commit ec04330

Browse files
committed
Raise exception for extremely long files names greater than 1000 characters
1 parent a5c070b commit ec04330

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

pymultinest/run.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,16 @@ def dumper(nSamples,nlive,nPar,
235235
# we need to make local copies here that are not thrown away
236236
s = outputfiles_basename.encode()
237237

238-
if len(outputfiles_basename + "post_equal_weights.txt") > 100:
238+
if len(outputfiles_basename + "post_equal_weights.txt") < 100:
239+
# 100 characters work for all MultiNest versions
240+
sb = create_string_buffer(s, 100)
241+
elif len(outputfiles_basename + "post_equal_weights.txt") > 1000:
242+
# file name is too long
243+
raise ValueError("Filenames must be less than 1000 characters long.")
244+
else:
239245
# try 1000 character length file name (this may cause MultiNest failure
240246
# or filename truncation if not using the latest MultiNest version)
241247
sb = create_string_buffer(s, 1000)
242-
else:
243-
# 100 characters work for all MultiNest versions
244-
sb = create_string_buffer(s, 100)
245248

246249
argtypes = [c_bool, c_bool, c_bool,
247250
c_int, c_double, c_double,
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Script to test MultiNest failure when running with an extremely long file name (> than 1000 characters)
2+
3+
import pytest
4+
from pymultinest.solve import solve
5+
6+
def test():
7+
with pytest.raises(ValueError):
8+
solve(lambda cube: -0.5 *(cube**2).sum(), lambda cube: cube, 2,
9+
resume=True, verbose=True,
10+
outputfiles_basename=1100*"a")
11+

0 commit comments

Comments
 (0)