[PATCH 03/13] simutil: Return early if file is not found

Denis Kenzior <[email protected]>
Newsgroups dev.linux.lists.ofono
Message-ID <[email protected]>
Certain Elementary Files are only present on SIM (2G) or USIMs (3G/4G).
If the file is not relevant to a given generation, its parent2g or
parent3g member will be set to 0.  Return early if the file is found to
be irrelevant for a given phase.  This also fixes a runtime sanitizer
warning:

src/simutil.c:1345:10: runtime error: null pointer passed as argument 1, which is declared to never be null
---
 src/simutil.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/simutil.c b/src/simutil.c
index a504e9aa8e3b..0fafcb7f77de 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -1302,7 +1302,7 @@ unsigned int sim_ef_db_get_path_2g(unsigned short id, unsigned char out_path[])
 
 	info = bsearch(GUINT_TO_POINTER((unsigned int) id), ef_db, nelem,
 				sizeof(struct sim_ef_info), find_ef_by_id);
-	if (info == NULL)
+	if (info == NULL || !info->parent2g)
 		return 0;
 
 	path[i++] = info->parent2g & 0xff;
@@ -1335,7 +1335,7 @@ unsigned int sim_ef_db_get_path_3g(unsigned short id, unsigned char out_path[])
 
 	info = bsearch(GUINT_TO_POINTER((unsigned int) id), ef_db, nelem,
 				sizeof(struct sim_ef_info), find_ef_by_id);
-	if (info == NULL)
+	if (info == NULL || !info->parent3g)
 		return 0;
 
 	path[i++] = info->parent3g & 0xff;
-- 
2.45.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.