jcs
/subtext
/amendments
/584
session: Avoid having to use strlen, check for null byte while walking
jcs made amendment 584 10 months ago
--- session.c Tue Dec 5 11:24:09 2023
+++ session.c Wed Jan 24 09:00:32 2024
@@ -791,7 +791,7 @@ session_output_view_or_printf(struct session *session,
va_list ap;
/* can't use bile_read_alloc because we need to null terminate */
- if (db->views[id] == NULL || strlen(db->views[id]) == 0) {
+ if (db->views[id] == NULL || db->views[id][0] == '\0') {
if (format == NULL)
return 0;
@@ -1310,7 +1310,7 @@ session_expand_template(struct session *session, const
char **ret)
{
static char curvar[128], matchvar[128];
- size_t tmpllen, retsize, retpos;
+ size_t retsize, retpos;
size_t vallen;
short n, invar = 0, varlen = 0, doif, sep;
char *varseek, *curvarpos, *val, *data;
@@ -1319,9 +1319,8 @@ session_expand_template(struct session *session, const
retsize = 0;
retpos = 0;
data = NULL;
- tmpllen = strlen(tmpl);
- for (n = 0; n < tmpllen; n++) {
+ for (n = 0; tmpl[n] != '\0'; n++) {
if (invar) {
if (!varlen && (tmpl[n] == ' ' || tmpl[n] == '\t'))
continue;