In practice these should never underflow, but in theory it's possible.
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
static void prune_init_slice(char *cg)
{
char *point;
static void prune_init_slice(char *cg)
{
char *point;
- point = cg + strlen(cg) - strlen(INITSCOPE);
- if (point < cg)
- return;
+ size_t cg_len = strlen(cg), initscope_len = strlen(INITSCOPE);
+
+ if (cg_len < initscope_len)
+ return;
+
+ point = cg + cg_len - initscope_len;
if (strcmp(point, INITSCOPE) == 0) {
if (point == cg)
*(point+1) = '\0';
if (strcmp(point, INITSCOPE) == 0) {
if (point == cg)
*(point+1) = '\0';
static void prune_init_scope(char *cg)
{
char *point;
static void prune_init_scope(char *cg)
{
char *point;
+ size_t cg_len, initscope_len;
- point = cg + strlen(cg) - strlen(INIT_SCOPE);
- if (point < cg)
+ cg_len = strlen(cg);
+ initscope_len = strlen(INIT_SCOPE);
+ if (cg_len < initscope_len)
+
+ point = cg + cg_len - initscope_len;
if (strcmp(point, INIT_SCOPE) == 0) {
if (point == cg)
*(point+1) = '\0';
if (strcmp(point, INIT_SCOPE) == 0) {
if (point == cg)
*(point+1) = '\0';