a68: fix %%< and %%> marks in snprintf calls

The function a68_mode_error_text computes a string that is then passed
to a68_error or a68_warning.  The later functions feed the resulting
string to the diagnostics machinery, which knows how to handle %< and
%>, but the *printf calls don't.  Therefore the %s have to be escaped
for %< and %> to be interpreted literally.

Signed-off-by: Jose E. Marchesi <jemarch@gnu.org>

	* a68-moids-diagnostics.cc (a68_mode_error_text): Properly escape
	%< and %> in snprintf calls.
This commit is contained in:
Jose E. Marchesi
2026-02-21 21:36:19 +01:00
parent f7d97316e5
commit 5feec11d51

View File

@@ -78,7 +78,7 @@ a68_mode_error_text (NODE_T *n, MOID_T *p, MOID_T *q, int context, int deflex, i
N++;
len = strlen (txt);
}
if (snprintf (TAIL (txt), ACTUAL_SNPRINTF_SIZE, "%<%s%>",
if (snprintf (TAIL (txt), ACTUAL_SNPRINTF_SIZE, "%%<%s%%>",
a68_moid_to_string (MOID (u), MOID_ERROR_WIDTH, n)) < 0)
gcc_unreachable ();
N++;
@@ -96,7 +96,7 @@ a68_mode_error_text (NODE_T *n, MOID_T *p, MOID_T *q, int context, int deflex, i
gcc_unreachable ();
len = strlen (txt);
}
if (snprintf (TAIL (txt), ACTUAL_SNPRINTF_SIZE, " cannot be coerced to %<%s%>",
if (snprintf (TAIL (txt), ACTUAL_SNPRINTF_SIZE, " cannot be coerced to %%<%s%%>",
a68_moid_to_string (q, MOID_ERROR_WIDTH, n)) < 0)
gcc_unreachable ();
}
@@ -137,7 +137,7 @@ a68_mode_error_text (NODE_T *n, MOID_T *p, MOID_T *q, int context, int deflex, i
}
}
len = strlen (txt);
if (snprintf (TAIL (txt), ACTUAL_SNPRINTF_SIZE, " cannot be coerced to %<%s%>",
if (snprintf (TAIL (txt), ACTUAL_SNPRINTF_SIZE, " cannot be coerced to %%<%s%%>",
a68_moid_to_string (SLICE (SUB (q)), MOID_ERROR_WIDTH, n)) < 0)
gcc_unreachable ();
}
@@ -171,7 +171,7 @@ a68_mode_error_text (NODE_T *n, MOID_T *p, MOID_T *q, int context, int deflex, i
gcc_unreachable ();
len = strlen (txt);
}
if (snprintf (TAIL (txt), ACTUAL_SNPRINTF_SIZE, "%<%s%>",
if (snprintf (TAIL (txt), ACTUAL_SNPRINTF_SIZE, "%%<%s%%>",
a68_moid_to_string (MOID (u), MOID_ERROR_WIDTH, n)) < 0)
gcc_unreachable ();
}
@@ -212,7 +212,7 @@ a68_mode_error_text (NODE_T *n, MOID_T *p, MOID_T *q, int context, int deflex, i
gcc_unreachable ();
len = strlen (txt);
}
if (snprintf (TAIL (txt), ACTUAL_SNPRINTF_SIZE, "%<%s%> cannot be coerced to %<%s%>",
if (snprintf (TAIL (txt), ACTUAL_SNPRINTF_SIZE, "%%<%s%%> cannot be coerced to %%<%s%%>",
a68_moid_to_string (MOID (u), MOID_ERROR_WIDTH, n),
a68_moid_to_string (MOID (v), MOID_ERROR_WIDTH, n)) < 0)
gcc_unreachable ();