diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 92b185e8dd..006391d894 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -544,7 +544,7 @@ static int virCgroupGetValueStr(virCgroupPtr group, VIR_DEBUG("Failed to read %s: %m\n", keypath); } else { /* Terminated with '\n' has sometimes harmful effects to the caller */ - if ((*value)[rc - 1] == '\n') + if (rc > 0 && (*value)[rc - 1] == '\n') (*value)[rc - 1] = '\0'; rc = 0;