[PATCH] osmo-hlr[master]: cosmetic: rename SL3_TXT macro, use osmo_strlcpy()

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Fri Oct 27 02:10:18 UTC 2017


Review at  https://gerrit.osmocom.org/4440

cosmetic: rename SL3_TXT macro, use osmo_strlcpy()

Rename SL3_TXT to more accurate copy_sqlite3_text_to_buf(), and use
osmo_strlcpy() instead of essentially dup'ing it.

The macro will also be used by hlr_db_tool.c in upcoming patch. This patch
prepares for a move to db.h.

Change-Id: I1dadeddddcfe0109195c09c0e706201b0df009cc
---
M src/db_hlr.c
1 file changed, 14 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/40/4440/1

diff --git a/src/db_hlr.c b/src/db_hlr.c
index ef01428..bae9a5a 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -35,12 +35,15 @@
 
 #define LOGHLR(imsi, level, fmt, args ...)	LOGP(DAUC, level, "IMSI='%s': " fmt, imsi, ## args)
 
-#define SL3_TXT(x, stmt, idx) 					\
-	do {							\
-		const char *_txt = (const char *) sqlite3_column_text(stmt, idx);\
-		if (_txt)					\
-			strncpy(x, _txt, sizeof(x));		\
-		x[sizeof(x)-1] = '\0';				\
+/*! Call sqlite3_column_text() and copy result to a char[].
+ * \param[out] buf  A char[] used as sizeof() arg(!) and osmo_strlcpy() target.
+ * \param[in] stmt  An sqlite3_stmt*.
+ * \param[in] idx   Index in stmt's returned columns.
+ */
+#define copy_sqlite3_text_to_buf(buf, stmt, idx) \
+	do { \
+		const char *_txt = (const char *) sqlite3_column_text(stmt, idx); \
+		osmo_strlcpy(buf, _txt, sizeof(buf)); \
 	} while (0)
 
 /*! Add new subscriber record to the HLR database.
@@ -410,12 +413,12 @@
 
 	/* obtain the various columns */
 	subscr->id = sqlite3_column_int64(stmt, 0);
-	SL3_TXT(subscr->imsi, stmt, 1);
-	SL3_TXT(subscr->msisdn, stmt, 2);
+	copy_sqlite3_text_to_buf(subscr->imsi, stmt, 1);
+	copy_sqlite3_text_to_buf(subscr->msisdn, stmt, 2);
 	/* FIXME: These should all be BLOBs as they might contain NUL */
-	SL3_TXT(subscr->vlr_number, stmt, 3);
-	SL3_TXT(subscr->sgsn_number, stmt, 4);
-	SL3_TXT(subscr->sgsn_address, stmt, 5);
+	copy_sqlite3_text_to_buf(subscr->vlr_number, stmt, 3);
+	copy_sqlite3_text_to_buf(subscr->sgsn_number, stmt, 4);
+	copy_sqlite3_text_to_buf(subscr->sgsn_address, stmt, 5);
 	subscr->periodic_lu_timer = sqlite3_column_int(stmt, 6);
 	subscr->periodic_rau_tau_timer = sqlite3_column_int(stmt, 7);
 	subscr->nam_cs = sqlite3_column_int(stmt, 8);

-- 
To view, visit https://gerrit.osmocom.org/4440
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1dadeddddcfe0109195c09c0e706201b0df009cc
Gerrit-PatchSet: 1
Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>


More information about the gerrit-log mailing list