From aa65a3cc11e4cdd52d9a6988d457311ca2aa5338 Mon Sep 17 00:00:00 2001
From: Gerardo Tauriello <gerardo.tauriello@unibas.ch>
Date: Wed, 19 Feb 2020 19:02:51 +0100
Subject: [PATCH] Allow short filenames in molck.

---
 tools/molck/main.cc | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/molck/main.cc b/tools/molck/main.cc
index 8507a1895..2016019cf 100644
--- a/tools/molck/main.cc
+++ b/tools/molck/main.cc
@@ -56,15 +56,15 @@ EntityHandle load_x(const String& file, const IOProfile& profile)
 {
   try {
     EntityHandle ent = CreateEntity();
-    if(file.compare(file.length() - 6, 6, ".mmcif") == 0 ||
-       file.compare(file.length() - 4, 4, ".cif") == 0){
-      MMCifReader reader(file,ent,profile);
+    const size_t fl = file.length();
+    if (   (fl > 6 && file.compare(fl - 6, 6, ".mmcif") == 0)
+        || (fl > 4 && file.compare(fl - 4, 4, ".cif") == 0)) {
+      MMCifReader reader(file, ent, profile);
       reader.Parse();
       return ent;
-    }
-    //if its not mmcif, we assume the file to be in pdb format without even
-    //looking at the filename
-    else{
+    } else {
+      // if its not mmcif, we assume the file to be in pdb format without even
+      // looking at the filename
       PDBReader reader(file, profile);
       if (reader.HasNext()) {
         reader.Import(ent);
-- 
GitLab