You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Segmentation fault on invalid SMARTS in RWMol::from_smarts() #18
I am still new to Rust as well as to rdkit, but I am having some problems with the conversion of SMARTS to RWMol. I hope you can help me with this.
I work on Mac and use a normal cargo binary crate. My code is very simple. I pass an invalid SMARTS to RWMol::from_smarts() and try to unwrap it. However, instead of having the code throw an error or panic, the execution gets interrupted and I get a segmentation fault:
let invalid_rwmol = RWMol::from_smarts("abdi###bhd").unwrap(); // just an arbitrary string println!("{:?}", invalid_rwmol);
I first started with matching the Result, but it would always come out as Ok(). When I debugged my code I noted that, although the method returned Ok(), the value of the RWMol pointer was null. However the pointer of the RWMol struct is private to the rdkit-crate so I cannot access it to see, if it is null. Also, since RWMol::from_smarts returns a Result<RWMol, Box>, I dont think it is the expected behavior.
The actual goal of my code was to check if some SMARTS I built are valid by simply creating a Mol-Struct out of them. If the SMARTS is not valid, I wanted to match the Err(). In Python this was easy, as Chem.MolFromSmarts() simply returns None if it wasn't successfull and I could go on form there.
As I am doing this as part of my Master's thesis, I would be very grateful for your help!
The invalid-SMARTS null-result defect is addressed in #57 with typed high-level errors and a regression. Empty SMARTS remains a valid empty query, following the discussion on #19. Keeping this issue open until the replacement implementation is merged and available.
Activity
aleebberg commentedon Dec 6, 2023
So I opened a PR to try to fix this problem.
@JJ-Pineda I would be very grateful, if you could check it out.
Fix segfault on invalid SMARTS and add RDKIT_PREFIX env var support
xrl commentedon Oct 9, 2026
The invalid-SMARTS null-result defect is addressed in #57 with typed high-level errors and a regression. Empty SMARTS remains a valid empty query, following the discussion on #19. Keeping this issue open until the replacement implementation is merged and available.