From ac94d11f7ba4d8f73a158ffb62e36975aee013d7 Mon Sep 17 00:00:00 2001
From: Eric Oulashin <eric.oulashin@gmail.com>
Date: Fri, 2 Feb 2024 16:45:20 -0800
Subject: [PATCH] DD file lister: More checks for pFileList[pIdx] and the
 'desc' property when getting the description

---
 xtrn/ddfilelister/ddfilelister.js      | 24 ++++++++++++++++++------
 xtrn/ddfilelister/readme.txt           |  4 ++--
 xtrn/ddfilelister/revision_history.txt |  2 ++
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/xtrn/ddfilelister/ddfilelister.js b/xtrn/ddfilelister/ddfilelister.js
index f452f16834..bfda9f42f2 100644
--- a/xtrn/ddfilelister/ddfilelister.js
+++ b/xtrn/ddfilelister/ddfilelister.js
@@ -96,6 +96,8 @@
  * 2023-11-11 Eric Oulashin     Version 2.15a
  *                              On start, if console.aborted is true (due to the user pressing Ctrl-C, etc.),
  *                              then return -1 to stop a file scan in progress.
+ * 2024-02-02 Eric Oulashin     Version 2.15b
+ *                              More checks for pFileList[pIdx] and the 'desc' property when getting the description
 */
 
 "use strict";
@@ -140,8 +142,8 @@ require("attr_conv.js", "convertAttrsToSyncPerSysCfg");
 
 
 // Lister version information
-var LISTER_VERSION = "2.15a";
-var LISTER_DATE = "2023-11-11";
+var LISTER_VERSION = "2.15b";
+var LISTER_DATE = "2024-02-02";
 
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -4975,7 +4977,9 @@ function numFileInfoLines(pFileList)
 //  pFormatInfo: An object containing format information returned by getTraditionalFileInfoFormatInfo()
 function getFileInfoLineArrayForTraditionalUI(pFileList, pIdx, pFormatInfo)
 {
-	if (!Array.isArray(pFileList) || typeof(pIdx) !== "number" || pIdx < 0 || pIdx > pFileList.length)
+	if (!Array.isArray(pFileList) || typeof(pIdx) !== "number" || pIdx < 0 || pIdx >= pFileList.length)
+		return [];
+	if (pFileList[pIdx] == undefined)
 		return [];
 
 	var userExtDescEnabled = ((user.settings & USER_EXTDESC) == USER_EXTDESC);
@@ -4983,7 +4987,10 @@ function getFileInfoLineArrayForTraditionalUI(pFileList, pIdx, pFormatInfo)
 	if (userExtDescEnabled)
 		descLines = getExtdFileDescArray(pFileList, pIdx);
 	else
-		descLines = [ pFileList[pIdx].desc.replace(/\r$/, "").replace(/\n$/, "").replace(/\r\n$/, "") ];
+	{
+		if (pFileList[pIdx].hasOwnProperty("desc") && typeof(pFileList[pIdx].desc) === "string")
+			descLines = [ pFileList[pIdx].desc.replace(/\r$/, "").replace(/\n$/, "").replace(/\r\n$/, "") ];
+	}
 	if (descLines.length == 0)
 		descLines.push("");
 
@@ -5026,7 +5033,9 @@ function getTraditionalFileInfoFormatInfo()
 //               if not available, the array will containin the non-extended description.
 function getExtdFileDescArray(pFileList, pIdx)
 {
-	if (!Array.isArray(pFileList) || typeof(pIdx) !== "number" || pIdx < 0 || pIdx > pFileList.length)
+	if (!Array.isArray(pFileList) || typeof(pIdx) !== "number" || pIdx < 0 || pIdx >= pFileList.length)
+		return [];
+	if (pFileList[pIdx] == undefined)
 		return [];
 
 	var extdDesc = "";
@@ -5040,7 +5049,10 @@ function getExtdFileDescArray(pFileList, pIdx)
 			extdDesc = fileMetadata.extdesc;
 	}
 	if (extdDesc.length == 0)
-		extdDesc = pFileList[pIdx].desc;
+	{
+		if (pFileList[pIdx].hasOwnProperty("desc") && typeof(pFileList[pIdx].desc) === "string")
+			extdDesc = pFileList[pIdx].desc;
+	}
 	var descLines = lfexpand(extdDesc).split("\r\n");
 	// Splitting as above can result in an extra empty last line
 	if (descLines[descLines.length-1].length == 0)
diff --git a/xtrn/ddfilelister/readme.txt b/xtrn/ddfilelister/readme.txt
index 6cc23c41c8..c40cc773d6 100644
--- a/xtrn/ddfilelister/readme.txt
+++ b/xtrn/ddfilelister/readme.txt
@@ -1,6 +1,6 @@
                         Digital Distortion File Lister
-                                 Version 2.15a
-                           Release date: 2023-11-11
+                                 Version 2.15b
+                           Release date: 2024-02-02
 
                                      by
 
diff --git a/xtrn/ddfilelister/revision_history.txt b/xtrn/ddfilelister/revision_history.txt
index 90e3097546..7fd4d632da 100644
--- a/xtrn/ddfilelister/revision_history.txt
+++ b/xtrn/ddfilelister/revision_history.txt
@@ -5,6 +5,8 @@ Revision History (change log)
 =============================
 Version  Date         Description
 -------  ----         -----------
+2.15b    2024-02-02   Code change/fix: More checks for pFileList[pIdx] and the
+                      'desc' property when getting the description
 2.15a    2023-11-11   On start, if console.aborted is true (due to the user
                       pressing Ctrl-C, etc.), then return -1 to stop a file
                       scan in progress.
-- 
GitLab