diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2018-06-29 16:56:45 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2018-06-29 16:56:45 +0100 |
commit | b2866c29156afdcad3ced4cc2001bbfe4302d81c (patch) | |
tree | f941c8d34578b475f0ec219a7642ab99510c8dc5 | |
parent | 75507f1aba6feb73ae43329922d51571550b9128 (diff) | |
parent | 230f1b31c5d58a852e1ac46e1ef05cfa7d5d9280 (diff) | |
download | qemu-b2866c29156afdcad3ced4cc2001bbfe4302d81c.zip qemu-b2866c29156afdcad3ced4cc2001bbfe4302d81c.tar.gz qemu-b2866c29156afdcad3ced4cc2001bbfe4302d81c.tar.bz2 |
Merge remote-tracking branch 'remotes/gkurz/tags/for-upstream' into staging
The Darwin host support still needs some more work. It won't make it for
soft-freeze, but I'd like these preparatory patches to be merged anyway.
# gpg: Signature made Fri 29 Jun 2018 11:39:04 BST
# gpg: using RSA key 71D4D5E5822F73D6
# gpg: Good signature from "Greg Kurz <groug@kaod.org>"
# gpg: aka "Gregory Kurz <gregory.kurz@free.fr>"
# gpg: aka "[jpeg image of size 3330]"
# Primary key fingerprint: B482 8BAF 9431 40CE F2A3 4910 71D4 D5E5 822F 73D6
* remotes/gkurz/tags/for-upstream:
9p: darwin: Explicitly cast comparisons of mode_t with -1
cutils: Provide strchrnul
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rwxr-xr-x | configure | 18 | ||||
-rw-r--r-- | hmp.c | 8 | ||||
-rw-r--r-- | hw/9pfs/9p-local.c | 6 | ||||
-rw-r--r-- | include/qemu/cutils.h | 8 | ||||
-rw-r--r-- | monitor.c | 8 | ||||
-rw-r--r-- | util/cutils.c | 15 | ||||
-rw-r--r-- | util/qemu-option.c | 6 | ||||
-rw-r--r-- | util/uri.c | 6 |
8 files changed, 53 insertions, 22 deletions
@@ -4797,6 +4797,21 @@ if compile_prog "" "" ; then fi ########################################## +# check if we have strchrnul + +strchrnul=no +cat > $TMPC << EOF +#include <string.h> +int main(void); +// Use a haystack that the compiler shouldn't be able to constant fold +char *haystack = (char*)&main; +int main(void) { return strchrnul(haystack, 'x') != &haystack[6]; } +EOF +if compile_prog "" "" ; then + strchrnul=yes +fi + +########################################## # check if trace backend exists $python "$source_path/scripts/tracetool.py" "--backends=$trace_backends" --check-backends > /dev/null 2> /dev/null @@ -6280,6 +6295,9 @@ fi if test "$sem_timedwait" = "yes" ; then echo "CONFIG_SEM_TIMEDWAIT=y" >> $config_host_mak fi +if test "$strchrnul" = "yes" ; then + echo "HAVE_STRCHRNUL=y" >> $config_host_mak +fi if test "$byteswap_h" = "yes" ; then echo "CONFIG_BYTESWAP_H=y" >> $config_host_mak fi @@ -2145,12 +2145,12 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) int has_hold_time = qdict_haskey(qdict, "hold-time"); int hold_time = qdict_get_try_int(qdict, "hold-time", -1); Error *err = NULL; - char *separator; + const char *separator; int keyname_len; while (1) { - separator = strchr(keys, '-'); - keyname_len = separator ? separator - keys : strlen(keys); + separator = qemu_strchrnul(keys, '-'); + keyname_len = separator - keys; /* Be compatible with old interface, convert user inputted "<" */ if (keys[0] == '<' && keyname_len == 1) { @@ -2187,7 +2187,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) keylist->value->u.qcode.data = idx; } - if (!separator) { + if (!*separator) { break; } keys = separator + 1; diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 5721eff..c30f4f2 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -65,7 +65,7 @@ int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags, assert(*path != '/'); head = g_strdup(path); - c = strchrnul(path, '/'); + c = qemu_strchrnul(path, '/'); if (*c) { /* Intermediate path element */ head[c - path] = 0; @@ -308,7 +308,7 @@ update_map_file: if (credp->fc_gid != -1) { gid = credp->fc_gid; } - if (credp->fc_mode != -1) { + if (credp->fc_mode != (mode_t)-1) { mode = credp->fc_mode; } if (credp->fc_rdev != -1) { @@ -414,7 +414,7 @@ static int local_set_xattrat(int dirfd, const char *path, FsCred *credp) return err; } } - if (credp->fc_mode != -1) { + if (credp->fc_mode != (mode_t)-1) { uint32_t tmp_mode = cpu_to_le32(credp->fc_mode); err = fsetxattrat_nofollow(dirfd, path, "user.virtfs.mode", &tmp_mode, sizeof(mode_t), 0); diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index a663340..274d419 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -122,6 +122,14 @@ int qemu_strnlen(const char *s, int max_len); * Returns: the pointer originally in @input. */ char *qemu_strsep(char **input, const char *delim); +#ifdef HAVE_STRCHRNUL +static inline const char *qemu_strchrnul(const char *s, int c) +{ + return strchrnul(s, c); +} +#else +const char *qemu_strchrnul(const char *s, int c); +#endif time_t mktimegm(struct tm *tm); int qemu_fdatasync(int fd); int fcntl_setfl(int fd, int flag); @@ -820,9 +820,7 @@ static int compare_cmd(const char *name, const char *list) p = list; for(;;) { pstart = p; - p = strchr(p, '|'); - if (!p) - p = pstart + strlen(pstart); + p = qemu_strchrnul(p, '|'); if ((p - pstart) == len && !memcmp(pstart, name, len)) return 1; if (*p == '\0') @@ -3491,9 +3489,7 @@ static void cmd_completion(Monitor *mon, const char *name, const char *list) p = list; for(;;) { pstart = p; - p = strchr(p, '|'); - if (!p) - p = pstart + strlen(pstart); + p = qemu_strchrnul(p, '|'); len = p - pstart; if (len > sizeof(cmd) - 2) len = sizeof(cmd) - 2; diff --git a/util/cutils.c b/util/cutils.c index 0de69e6..9205e09 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -545,6 +545,21 @@ int qemu_strtou64(const char *nptr, const char **endptr, int base, } /** + * Searches for the first occurrence of 'c' in 's', and returns a pointer + * to the trailing null byte if none was found. + */ +#ifndef HAVE_STRCHRNUL +const char *qemu_strchrnul(const char *s, int c) +{ + const char *e = strchr(s, c); + if (!e) { + e = s + strlen(s); + } + return e; +} +#endif + +/** * parse_uint: * * @s: String to parse diff --git a/util/qemu-option.c b/util/qemu-option.c index ba44a08..19761e3 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -77,11 +77,7 @@ const char *get_opt_value(const char *p, char **value) *value = NULL; while (1) { - offset = strchr(p, ','); - if (!offset) { - offset = p + strlen(p); - } - + offset = qemu_strchrnul(p, ','); length = offset - p; if (*offset != '\0' && *(offset + 1) == ',') { length++; @@ -52,6 +52,7 @@ */ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qemu/uri.h" @@ -2266,10 +2267,7 @@ struct QueryParams *query_params_parse(const char *query) /* Find the next separator, or end of the string. */ end = strchr(query, '&'); if (!end) { - end = strchr(query, ';'); - } - if (!end) { - end = query + strlen(query); + end = qemu_strchrnul(query, ';'); } /* Find the first '=' character between here and end. */ |