commit 2b8f86e5ac11b7b938b01aa6fc309be5dca1abe1
parent 2c37705a0739bdfbc1c77fd4df177ff7eda1277f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 26 Jun 2026 16:07:41 +0200
Update to the uolecule ID checks
In fact, this check was completely incorrect. A null ID was considered
valid when it should not have been, as was an ID located beyond the last
valid ID, which also led to unauthorized memory access.
As a result, metadata listing new molecules was not correctly flagged as
unsupported. And the library crashed.
Diffstat:
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/shtr_isotope_metadata.c b/src/shtr_isotope_metadata.c
@@ -46,7 +46,8 @@ struct molecule {
size_t isotopes_range[2]; /* Range of the [1st and last[ isotopes */
int id; /* Unique identifier of the molecule */
};
-#define MOLECULE_IS_VALID(Molecule) ((Molecule)->id >= 0)
+#define MOLECULE_IS_VALID(Molecule) \
+ (((Molecule)->id > 0) && ((Molecule)->id < SHTR_MAX_MOLECULE_COUNT))
static INLINE void
molecule_clear(struct molecule* molecule)