[clang-tidy] fix wrong *cmp usage

Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2020-04-18 22:32:29 -07:00
parent 042f62dfc5
commit ad296391f9
No known key found for this signature in database
GPG Key ID: 36D31CFA845F0E3B
33 changed files with 56 additions and 56 deletions

View File

@ -819,10 +819,10 @@ static struct fsck_instance *wait_one(int flags)
for (inst2 = instance_list; inst2; inst2 = inst2->next) {
if (inst2->flags & FLAG_DONE)
continue;
if (strcmp(inst2->type, "ext2") &&
if (strcmp(inst2->type, "ext2") != 0 &&
strcmp(inst2->type, "ext3") &&
strcmp(inst2->type, "ext4") &&
strcmp(inst2->type, "ext4dev"))
strcmp(inst2->type, "ext4") != 0 &&
strcmp(inst2->type, "ext4dev") != 0)
continue;
/*
* If we've just started the fsck, wait a tiny
@ -903,8 +903,8 @@ static int fsck_device(struct libmnt_fs *fs, int interactive)
if (type && strcmp(type, "auto") != 0)
;
else if (fstype && strncmp(fstype, "no", 2) &&
strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4) &&
else if (fstype && strncmp(fstype, "no", 2) != 0 &&
strncmp(fstype, "opts=", 5) != 0 && strncmp(fstype, "loop", 4) != 0 &&
!strchr(fstype, ','))
type = fstype;
else

View File

@ -976,7 +976,7 @@ check_file(struct minix_inode *dir, unsigned int offset) {
inode = get_inode(ino);
name_depth--;
if (!offset) {
if (!inode || strcmp(".", name)) {
if (!inode || strcmp(".", name) != 0) {
get_current_name();
printf(_("%s: bad directory: '.' isn't first\n"),
current_name);
@ -985,7 +985,7 @@ check_file(struct minix_inode *dir, unsigned int offset) {
return;
}
if (offset == dirsize) {
if (!inode || strcmp("..", name)) {
if (!inode || strcmp("..", name) != 0) {
get_current_name();
printf(_("%s: bad directory: '..' isn't second\n"),
current_name);
@ -1049,7 +1049,7 @@ check_file2(struct minix2_inode *dir, unsigned int offset) {
inode = get_inode2(ino);
name_depth--;
if (!offset) {
if (!inode || strcmp(".", name)) {
if (!inode || strcmp(".", name) != 0) {
get_current_name();
printf(_("%s: bad directory: '.' isn't first\n"),
current_name);
@ -1058,7 +1058,7 @@ check_file2(struct minix2_inode *dir, unsigned int offset) {
return;
}
if (offset == dirsize) {
if (!inode || strcmp("..", name)) {
if (!inode || strcmp("..", name) != 0) {
get_current_name();
printf(_("%s: bad directory: '..' isn't second\n"),
current_name);

View File

@ -245,7 +245,7 @@ static int get_max_partno(const char *disk, dev_t devno)
if (d->d_type != DT_DIR && d->d_type != DT_UNKNOWN)
continue;
#endif
if (strncmp(parent, d->d_name, strlen(parent)))
if (strncmp(parent, d->d_name, strlen(parent)) != 0)
continue;
snprintf(path, sizeof(path), "%s/partition", d->d_name);

View File

@ -272,7 +272,7 @@ static int is_swap_device(const char *file)
/* Skip the first line */
if (!fgets(buf, sizeof(buf), f))
goto leave;
if (*buf && strncmp(buf, "Filename\t", 9))
if (*buf && strncmp(buf, "Filename\t", 9) != 0)
/* Linux <=2.6.19 contained a bug in the /proc/swaps
* code where the header would not be displayed
*/

View File

@ -1806,7 +1806,7 @@ int loopdev_count_by_backing_file(const char *filename, char **loopdev)
while(loopcxt_next(&lc) == 0) {
char *backing = loopcxt_get_backing_file(&lc);
if (!backing || strcmp(backing, filename)) {
if (!backing || strcmp(backing, filename) != 0) {
free(backing);
continue;
}

View File

@ -37,7 +37,7 @@ blkid_probe get_swap_prober(const char *devname)
/* Only the SWAPSPACE2 is supported. */
if (blkid_probe_lookup_value(pr, "VERSION", &version, NULL) == 0
&& version
&& strcmp(version, stringify_value(SWAP_VERSION)))
&& strcmp(version, stringify_value(SWAP_VERSION)) != 0)
warnx(_("%s: unsupported swap version '%s'"),
devname, version);
else

View File

@ -869,7 +869,7 @@ dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char
goto done;
sysfs_devname_dev_to_sys(_name);
if (parent && strncmp("dm-", name, 3)) {
if (parent && strncmp("dm-", name, 3) != 0) {
/*
* Create path to /sys/block/<parent>/<name>/dev
*/

View File

@ -58,7 +58,7 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
/* search by name */
list_for_each(p, &cache->bic_devs) {
tmp = list_entry(p, struct blkid_struct_dev, bid_devs);
if (strcmp(tmp->bid_name, devname))
if (strcmp(tmp->bid_name, devname) != 0)
continue;
dev = tmp;
break;
@ -70,7 +70,7 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
DBG(DEVNAME, ul_debug("search canonical %s", cn));
list_for_each(p, &cache->bic_devs) {
tmp = list_entry(p, struct blkid_struct_dev, bid_devs);
if (strcmp(tmp->bid_name, cn))
if (strcmp(tmp->bid_name, cn) != 0)
continue;
dev = tmp;
@ -120,13 +120,13 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
if (dev2->bid_flags & BLKID_BID_FL_VERIFIED)
continue;
if (!dev->bid_type || !dev2->bid_type ||
strcmp(dev->bid_type, dev2->bid_type))
strcmp(dev->bid_type, dev2->bid_type) != 0)
continue;
if (dev->bid_label && dev2->bid_label &&
strcmp(dev->bid_label, dev2->bid_label))
strcmp(dev->bid_label, dev2->bid_label) != 0)
continue;
if (dev->bid_uuid && dev2->bid_uuid &&
strcmp(dev->bid_uuid, dev2->bid_uuid))
strcmp(dev->bid_uuid, dev2->bid_uuid) != 0)
continue;
if ((dev->bid_label && !dev2->bid_label) ||
(!dev->bid_label && dev2->bid_label) ||
@ -160,7 +160,7 @@ static int is_dm_leaf(const char *devname)
while ((de = readdir(dir)) != NULL) {
if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..") ||
!strcmp(de->d_name, devname) ||
strncmp(de->d_name, "dm-", 3) ||
strncmp(de->d_name, "dm-", 3) != 0 ||
strlen(de->d_name) > sizeof(path)-32)
continue;
sprintf(path, "/sys/block/%s/slaves", de->d_name);
@ -544,7 +544,7 @@ static int probe_all(blkid_cache cache, int only_if_new)
* dev, and the device's base name has changed,
* check last as well.
*/
if (lens[last] && strncmp(ptnames[last], ptname, lens[last])) {
if (lens[last] && strncmp(ptnames[last], ptname, lens[last]) != 0) {
DBG(DEVNAME, ul_debug(" whole dev %s, devno 0x%04X",
ptnames[last], (unsigned int) devs[last]));
probe_one(cache, ptnames[last], devs[last], 0,

View File

@ -164,7 +164,7 @@ static int parse_extended(blkid_probe pr, blkid_partlist ls,
if (!IS_ACTIVE(xrs->part[i+1]))
break;
if (memcmp(xrs->part[i+1].id, "XGM", 3))
if (memcmp(xrs->part[i+1].id, "XGM", 3) != 0)
return 0;
xstart = x0start + be32_to_cpu(xrs->part[i+1].start);

View File

@ -162,7 +162,7 @@ static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_
if (!buf_mft)
return errno ? -errno : 1;
if (memcmp(buf_mft, "FILE", 4))
if (memcmp(buf_mft, "FILE", 4) != 0)
return 1;
off += MFT_RECORD_VOLUME * mft_record_size;
@ -171,7 +171,7 @@ static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_
if (!buf_mft)
return errno ? -errno : 1;
if (memcmp(buf_mft, "FILE", 4))
if (memcmp(buf_mft, "FILE", 4) != 0)
return 1;
/* return if caller does not care about UUID and LABEL */

View File

@ -425,7 +425,7 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
}
}
if (boot_label && memcmp(boot_label, no_name, 11))
if (boot_label && memcmp(boot_label, no_name, 11) != 0)
blkid_probe_set_id_label(pr, "LABEL_FATBOOT", boot_label, 11);
if (vol_label)

View File

@ -73,7 +73,7 @@ int blkid_dev_has_tag(blkid_dev dev, const char *type,
tag = blkid_find_tag_dev(dev, type);
if (!value)
return (tag != NULL);
if (!tag || strcmp(tag->bit_val, value))
if (!tag || strcmp(tag->bit_val, value) != 0)
return 0;
return 1;
}

View File

@ -413,7 +413,7 @@ static int sgi_check_bootfile(struct fdisk_context *cxt, const char *name)
}
if (strncmp(name, (char *) sgilabel->boot_file,
sizeof(sgilabel->boot_file))) {
sizeof(sgilabel->boot_file)) != 0) {
fdisk_warnx(cxt, _("Be aware that the bootfile is not checked "
"for existence. SGI's default is \"/unix\", "
"and for backup \"/unix.save\"."));

View File

@ -1808,7 +1808,7 @@ int mnt_context_prepare_srcpath(struct libmnt_context *cxt)
* Source is PATH (canonicalize)
*/
path = mnt_resolve_path(src, cache);
if (path && strcmp(path, src))
if (path && strcmp(path, src) != 0)
rc = mnt_fs_set_source(cxt->fs, path);
}

View File

@ -388,7 +388,7 @@ static int is_associated_fs(const char *devname, struct libmnt_fs *fs)
int flags = 0;
/* check if it begins with /dev/loop */
if (strncmp(devname, _PATH_DEV_LOOP, sizeof(_PATH_DEV_LOOP) - 1))
if (strncmp(devname, _PATH_DEV_LOOP, sizeof(_PATH_DEV_LOOP) - 1) != 0)
return 0;
src = mnt_fs_get_srcpath(fs);

View File

@ -249,7 +249,7 @@ const struct libmnt_optmap *mnt_optmap_get_entry(
}
continue;
}
if (strncmp(ent->name, name, namelen))
if (strncmp(ent->name, name, namelen) != 0)
continue;
p = ent->name + namelen;
if (*p == '\0' || *p == '=' || *p == '[') {

View File

@ -1077,7 +1077,7 @@ int mnt_optstr_fix_user(char **optstr)
if (!username)
return -ENOMEM;
if (!ol.valsz || (ol.value && strncmp(ol.value, username, ol.valsz))) {
if (!ol.valsz || (ol.value && strncmp(ol.value, username, ol.valsz) != 0)) {
if (ol.valsz)
/* remove old value */
mnt_optstr_remove_option_at(optstr, ol.value, ol.end);

View File

@ -277,7 +277,7 @@ int mnt_diff_tables(struct libmnt_tabdiff *df, struct libmnt_table *old_tab,
*f1 = mnt_fs_get_fs_options(o_fs),
*f2 = mnt_fs_get_fs_options(fs);
if ((v1 && v2 && strcmp(v1, v2)) || (f1 && f2 && strcmp(f1, f2)))
if ((v1 && v2 && strcmp(v1, v2) != 0) || (f1 && f2 && strcmp(f1, f2) != 0))
tabdiff_add_entry(df, o_fs, fs, MNT_TABDIFF_REMOUNT);
}
}

View File

@ -885,7 +885,7 @@ static int mnt_table_parse_dir_filter(const struct dirent *d)
namesz = strlen(d->d_name);
if (!namesz || namesz < MNT_MNTTABDIR_EXTSIZ + 1 ||
strcmp(d->d_name + (namesz - MNT_MNTTABDIR_EXTSIZ),
MNT_MNTTABDIR_EXT))
MNT_MNTTABDIR_EXT) != 0)
return 0;
/* Accept this */

View File

@ -377,7 +377,7 @@ static void init_tty(struct login_context *cxt)
*/
if (!cxt->tty_path || !*cxt->tty_path ||
lstat(cxt->tty_path, &st) != 0 || !S_ISCHR(st.st_mode) ||
(st.st_nlink > 1 && strncmp(cxt->tty_path, "/dev/", 5)) ||
(st.st_nlink > 1 && strncmp(cxt->tty_path, "/dev/", 5) != 0) ||
access(cxt->tty_path, R_OK | W_OK) != 0) {
syslog(LOG_ERR, _("FATAL: bad tty"));

View File

@ -1149,7 +1149,7 @@ int su_main(int argc, char **argv, int mode)
shell = getenv("SHELL");
if (shell
&& strcmp(shell, su->pwd->pw_shell)
&& strcmp(shell, su->pwd->pw_shell) != 0
&& getuid() != 0
&& is_restricted_shell(su->pwd->pw_shell)) {
/* The user being su'd to has a nonstandard shell, and

View File

@ -524,7 +524,7 @@ static char *get_data(struct libmnt_fs *fs, int num)
if (spec && (flags & FL_EVALUATE))
spec = cn = mnt_resolve_spec(spec, cache);
}
if (root && spec && !(flags & FL_NOFSROOT) && strcmp(root, "/"))
if (root && spec && !(flags & FL_NOFSROOT) && strcmp(root, "/") != 0)
xasprintf(&str, "%s[%s]", spec, root);
else if (spec)
str = xstrdup(spec);

View File

@ -296,7 +296,7 @@ static void process_path(struct hardlink_ctl *ctl, const char *name)
close(fd2);
return;
}
if (memcmp(ctl->iobuf1, ctl->iobuf2, rsize))
if (memcmp(ctl->iobuf1, ctl->iobuf2, rsize) != 0)
break;
}
close(fd2);

View File

@ -136,7 +136,7 @@ static int lookup(char *buf, char *pattern, char **value)
return 0;
len = strlen(pattern);
if (strncmp(buf, pattern, len))
if (strncmp(buf, pattern, len) != 0)
return 0;
p = buf + len;

View File

@ -133,7 +133,7 @@ static int chmem_size(struct chmem_desc *desc, int enable, int zone_id)
zn = zone_names[zone_id];
if (enable && !strcasestr(line, zn))
continue;
if (!enable && strncasecmp(line, zn, strlen(zn)))
if (!enable && strncasecmp(line, zn, strlen(zn)) != 0)
continue;
} else if (enable) {
/* By default, use zone Movable for online, if valid */
@ -218,7 +218,7 @@ static int chmem_range(struct chmem_desc *desc, int enable, int zone_id)
warnx(_("%s enable failed: Zone mismatch"), str);
continue;
}
if (!enable && strncasecmp(line, zn, strlen(zn))) {
if (!enable && strncasecmp(line, zn, strlen(zn)) != 0) {
warnx(_("%s disable failed: Zone mismatch"), str);
continue;
}
@ -251,7 +251,7 @@ static int chmem_range(struct chmem_desc *desc, int enable, int zone_id)
static int filter(const struct dirent *de)
{
if (strncmp("memory", de->d_name, 6))
if (strncmp("memory", de->d_name, 6) != 0)
return 0;
return isdigit_string(de->d_name + 6);
}

View File

@ -209,7 +209,7 @@ void arm_cpu_decode(struct lscpu_desc *desc)
if (desc->vendor == NULL || desc->model == NULL)
return;
if ((strncmp(desc->vendor,"0x",2) || strncmp(desc->model,"0x",2) ))
if ((strncmp(desc->vendor,"0x",2) != 0 || strncmp(desc->model,"0x",2) ))
return;
errno = 0;

View File

@ -277,7 +277,7 @@ lookup(char *line, char *pattern, char **value)
return 0;
/* pattern */
if (strncmp(line, pattern, len))
if (strncmp(line, pattern, len) != 0)
return 0;
/* white spaces */
@ -322,7 +322,7 @@ lookup_cache(char *line, struct lscpu_desc *desc)
int level;
/* Make sure line starts with "cache<nr> :" */
if (strncmp(line, "cache", 5))
if (strncmp(line, "cache", 5) != 0)
return 0;
for (p = line + 5; isdigit(*p); p++);
for (; isspace(*p); p++);

View File

@ -344,7 +344,7 @@ static int memory_block_get_node(struct lsmem *lsmem, char *name)
node = -1;
while ((de = readdir(dir)) != NULL) {
if (strncmp("node", de->d_name, 4))
if (strncmp("node", de->d_name, 4) != 0)
continue;
if (!isdigit_string(de->d_name + 4))
continue;
@ -459,7 +459,7 @@ static void read_info(struct lsmem *lsmem)
static int memory_block_filter(const struct dirent *de)
{
if (strncmp("memory", de->d_name, 6))
if (strncmp("memory", de->d_name, 6) != 0)
return 0;
return isdigit_string(de->d_name + 6);
}

View File

@ -262,12 +262,12 @@ static void verify_arch_domain(struct arch_domain *dom, const char *wanted)
return;
uname(&un);
if (strcmp(un.machine, dom->result_arch)) {
if (strcmp(dom->result_arch, "i386")
|| (strcmp(un.machine, "i486")
if (strcmp(un.machine, dom->result_arch) != 0) {
if (strcmp(dom->result_arch, "i386") != 0
|| (strcmp(un.machine, "i486") != 0
&& strcmp(un.machine, "i586")
&& strcmp(un.machine, "i686")
&& strcmp(un.machine, "athlon")))
&& strcmp(un.machine, "i686") != 0
&& strcmp(un.machine, "athlon") != 0))
errx(EXIT_FAILURE, _("Kernel cannot set architecture to %s"), wanted);
}
}

View File

@ -580,7 +580,7 @@ static char *replace_u(char *str, char *username)
size_t sz;
char *tp, *old = entry;
if (memcmp(p, "\\u", 2)) {
if (memcmp(p, "\\u", 2) != 0) {
p++;
continue; /* no \u */
}
@ -1732,7 +1732,7 @@ static int issuedir_filter(const struct dirent *d)
namesz = strlen(d->d_name);
if (!namesz || namesz < ISSUEDIR_EXTSIZ + 1 ||
strcmp(d->d_name + (namesz - ISSUEDIR_EXTSIZ), ISSUEDIR_EXT))
strcmp(d->d_name + (namesz - ISSUEDIR_EXTSIZ), ISSUEDIR_EXT) != 0)
return 0;
/* Accept this */

View File

@ -275,7 +275,7 @@ static void do_write(const struct write_control *ctl)
tm = localtime(&now);
/* print greeting */
printf("\r\n\a\a\a");
if (strcmp(login, pwuid))
if (strcmp(login, pwuid) != 0)
printf(_("Message from %s@%s (as %s) on %s at %02d:%02d ..."),
login, host, pwuid, ctl->src_tty_name,
tm->tm_hour, tm->tm_min);

View File

@ -33,7 +33,7 @@ int main(int argc, const char *argv[])
}
for (i = 0; i < sizeof(errors)/sizeof(*errors); i++) {
if (strcmp(errors[i].str, argv[1]))
if (strcmp(errors[i].str, argv[1]) != 0)
continue;
puts(strerror(errors[i].error));
return 0;

View File

@ -377,7 +377,7 @@ get(struct hexdump *hex)
hex->length -= n;
if (!(need -= n)) {
if (vflag == ALL || vflag == FIRST ||
memcmp(curp, savp, hex->blocksize)) {
memcmp(curp, savp, hex->blocksize) != 0) {
if (vflag == DUP || vflag == FIRST)
vflag = WAIT;
return(curp);