There's new commit in glibc [1] which makes memchr(), strchr(),
strrchr(), strpbrk() and strstr() reflect type of the input
string. If it's a constant string, then the return type of these
functions is also 'const char *'. But this change tickles
-Wincompatible-pointer-types-discards-qualifiers warning.
And indeed, there are some places where we use a 'char *' typed
variable to store the retval, or even misuse the fact 'char *' is
returned and modify const string.
To fix this, a couple of different approaches is used:
a) switch variable type to 'const char *',
b) switch argument to 'char *' (in a few places we have
strdup()-ed) the const string already,
c) strdup() the string and use b).
1: https://sourceware.org/git/?p=glibc.git;a=commit;h=
cd748a63ab1a7ae846175c532a3daab341c62690
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Jaroslav Suchanek <jsuchane@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
g_autoptr(virInterfaceDef) ifacedef = NULL;
unsigned int mtu;
const char *mtu_str;
- char *vlan_parent_dev = NULL;
+ const char *vlan_parent_dev = NULL;
const char *devtype;
/* Allocate our interface definition structure */
xenParseSxprChar(const char *value,
const char *tty)
{
- const char *prefix;
+ g_autofree char *prefix = NULL;
char *tmp;
virDomainChrDef *def;
if (!(def = virDomainChrDefNew(NULL)))
return NULL;
- prefix = value;
+ prefix = g_strdup(value);
if (g_path_is_absolute(value)) {
def->source->type = VIR_DOMAIN_CHR_TYPE_DEV;
def->source->data.file.path = g_strdup(value);
} else {
- if ((tmp = strchr(value, ':')) != NULL) {
+ if ((tmp = strchr(prefix, ':')) != NULL) {
*tmp = '\0';
value = tmp + 1;
}
static int
xenParseVifBridge(virDomainNetDef *net, const char *bridge)
{
- char *vlanstr;
+ const char *vlanstr;
unsigned int tag;
if ((vlanstr = strchr(bridge, '.'))) {
for (keyval = keyvals; keyval && *keyval; keyval++) {
const char *key = *keyval;
- char *val = strchr(key, '=');
+ const char *val = strchr(key, '=');
virSkipSpaces(&key);
src = virDomainDiskGetSource(disk);
if (src) {
size_t len;
+ const char *sep;
+
/* The main type phy:, file:, tap: ... */
- if ((tmp = strchr(src, ':')) != NULL) {
- len = tmp - src;
+ if ((sep = strchr(src, ':')) != NULL) {
+ len = sep - src;
tmp = g_strndup(src, len);
virDomainDiskSetDriver(disk, tmp);
STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap2")) {
char *driverType;
- if (!(tmp = strchr(src, ':')))
+ if (!(sep = strchr(src, ':')))
goto error;
- len = tmp - src;
+ len = sep - src;
driverType = g_strndup(src, len);
udevGetCCWAddress(const char *sysfs_path,
virNodeDevCapData *data)
{
- char *p;
+ const char *p;
g_autofree virCCWDeviceAddress *ccw_addr = g_new0(virCCWDeviceAddress, 1);
if ((p = strrchr(sysfs_path, '/')) == NULL ||
const char *chainprefixes = opaque;
for (i = 0; lines[i] != NULL; i++) {
- char *tmp = strstr(lines[i], "-j ");
+ const char *tmp = strstr(lines[i], "-j ");
VIR_DEBUG("Considering '%s'", lines[i]);
char newchain[MAX_CHAINNAME_LENGTH];
for (i = 0; lines[i] != NULL; i++) {
- char *tmp = strstr(lines[i], "-j ");
+ const char *tmp = strstr(lines[i], "-j ");
VIR_DEBUG("Considering '%s'", lines[i]);
/*VIR_DEBUG("Data %d bytes [%s]", len, data);*/
while (used < len) {
- char *nl = strstr(data + used, LINE_ENDING);
+ const char *nl = strstr(data + used, LINE_ENDING);
if (nl) {
int got = nl - (data + used);
size_t i;
g_autofree char *output = NULL;
g_auto(GStrv) lines = NULL;
- const char *line;
+ char *line;
g_autoptr(virCommand) cmd = virCommandNewArgList(nbdkit->path,
"--dump-config",
NULL);
/* fill data structures for auth callback */
for (i = 0; i < num_prompts; i++) {
- askcred[i].prompt = g_strdup((char*)prompts[i].text);
+ char *prompt = g_strdup((char*)prompts[i].text);
/* remove colon and trailing spaces from prompts, as default behavior
* of libvirt's auth callback is to add them */
- if ((tmp = strrchr(askcred[i].prompt, ':')))
+ if ((tmp = strrchr(prompt, ':')))
*tmp = '\0';
+ askcred[i].prompt = prompt;
askcred[i].type = prompts[i].echo ? credtype_echo : credtype_noecho;
}
const char *block_name,
char **block_device)
{
- char *blockp = NULL;
+ const char *blockp = NULL;
/* old-style; just parse out the sd */
if (!(blockp = strrchr(block_name, ':'))) {
static bool
virStorageSourceBackinStoreStringIsFile(const char *backing)
{
- char *colon;
- char *slash;
+ const char *colon;
+ const char *slash;
if (!backing)
return false;
virCgroupSetValueRaw(const char *path,
const char *value)
{
- char *tmp;
+ const char *tmp;
VIR_DEBUG("Set path '%s' to value '%s'", path, value);
if (virFileWriteStr(path, value, 0) < 0) {
virFileSanitizePath(const char *path)
{
const char *cur = path;
- char *uri;
+ const char *uri;
char *cleanpath;
int idx = 0;
char **key)
{
int status;
- const char *serial;
- const char *port;
+ char *serial;
+ char *port;
g_autofree char *outbuf = NULL;
g_autoptr(virCommand) cmd = NULL;
virSysinfoParsePPCSystem(const char *base, virSysinfoSystemDef **sysdef)
{
int ret = -1;
- char *eol = NULL;
+ const char *eol = NULL;
const char *cur;
virSysinfoSystemDef *def;
virSysinfoParsePPCProcessor(const char *base, virSysinfoDef *ret)
{
const char *cur;
- char *eol, *tmp_base;
+ const char *eol, *tmp_base;
virSysinfoProcessorDef *processor;
while ((tmp_base = strstr(base, "processor")) != NULL) {
virSysinfoParseARMSystem(const char *base, virSysinfoSystemDef **sysdef)
{
int ret = -1;
- char *eol = NULL;
+ const char *eol = NULL;
const char *cur;
virSysinfoSystemDef *def;
virSysinfoParseARMProcessor(const char *base, virSysinfoDef *ret)
{
const char *cur;
- char *eol, *tmp_base;
+ const char *eol, *tmp_base;
virSysinfoProcessorDef *processor;
char *processor_type = NULL;
const char *str,
const char *illegal)
{
- char *c;
+ const char *c;
+
if ((c = strpbrk(str, illegal))) {
virReportError(VIR_ERR_XML_DETAIL,
_("invalid char in %1$s: %2$c"), nodeName, *c);
static int
vmwareParsePath(const char *path, char **directory, char **filename)
{
- char *separator;
+ const char *separator;
separator = strrchr(path, '/');
case VSH_OT_ALIAS: {
size_t j;
g_autofree char *name = NULL;
- char *p;
+ const char *p;
if (opt->required ||
opt->positional ||
alias of option and its default value */
alias = g_strdup(n->def->help);
name = alias;
- if ((value = strchr(name, '='))) {
+ if ((value = strchr(alias, '='))) {
*value = '\0';
if (*optstr) {
if (report)
* value
* -- (terminate accepting '--option', fill only positional args)
*/
- const char *optionname = tkdata + 2;
+ char *optionname = tkdata + 2;
char *sep;
if (!STRPREFIX(tkdata, "--")) {