From ecbf5b10d4fe53306be87f95ce5c04b2d93af8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Fri, 13 Sep 2019 16:20:39 +0300 Subject: [PATCH] Fix infinite loop in empty lattice modes generation Former-commit-id: 1349035090712935a0d77d64c175e4358fb4d487 --- qpms/lattices2d.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qpms/lattices2d.c b/qpms/lattices2d.c index 0f5978c..6249f00 100644 --- a/qpms/lattices2d.c +++ b/qpms/lattices2d.c @@ -909,8 +909,13 @@ size_t qpms_emptylattice2_modes_maxfreq(double **target_freqs, size_t generated = 0; PGenReturnDataBulk rd; - while((rd = PGen_fetch_cart2(&Kgen, capacity - generated, Kpoints + generated)).flags & PGEN_NOTDONE) + while((rd = PGen_fetch_cart2(&Kgen, capacity - generated, Kpoints + generated)).flags & PGEN_NOTDONE) { generated += rd.generated; + if (capacity <= generated) { + PGen_destroy(&Kgen); + break; + } + } double *thefreqs; QPMS_CRASHING_MALLOC(thefreqs, generated * sizeof(double));