Message ID | 082b20c6ae4ab03961beb8a174c4ea7055a98518.1411703316.git.peter.crosthwaite@xilinx.com |
---|---|
State | New |
Headers | show |
Il 26/09/2014 07:18, Peter Crosthwaite ha scritto: > Create a valid qobject even if the input string is null. > qstring->string will be NULL and length will be 0. > > This prepares support for clearing of QOM Link properties > where NULL canonical path string will be passes through > this API. > > Reviewed-by: Alexander Graf <agraf@suse.de> > Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> > --- This shouldn't be necessary if you use "". Paolo
Am 26.09.2014 um 15:27 schrieb Paolo Bonzini: > Il 26/09/2014 07:18, Peter Crosthwaite ha scritto: >> Create a valid qobject even if the input string is null. >> qstring->string will be NULL and length will be 0. >> >> This prepares support for clearing of QOM Link properties >> where NULL canonical path string will be passes through >> this API. >> >> Reviewed-by: Alexander Graf <agraf@suse.de> >> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> >> --- > > This shouldn't be necessary if you use "". Ping? I have patches 1-3 queued and am waiting how to proceed with this series. Thanks, Andreas
diff --git a/qobject/qstring.c b/qobject/qstring.c index 607b7a1..a15ffed 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -48,14 +48,16 @@ QString *qstring_from_substr(const char *str, int start, int end) { QString *qstring; - qstring = g_malloc(sizeof(*qstring)); + qstring = g_malloc0(sizeof(*qstring)); qstring->length = end - start + 1; qstring->capacity = qstring->length; - qstring->string = g_malloc(qstring->capacity + 1); - memcpy(qstring->string, str + start, qstring->length); - qstring->string[qstring->length] = 0; + if (str) { + qstring->string = g_malloc(qstring->capacity + 1); + memcpy(qstring->string, str + start, qstring->length); + qstring->string[qstring->length] = 0; + } QOBJECT_INIT(qstring, &qstring_type); @@ -69,7 +71,7 @@ QString *qstring_from_substr(const char *str, int start, int end) */ QString *qstring_from_str(const char *str) { - return qstring_from_substr(str, 0, strlen(str) - 1); + return qstring_from_substr(str, 0, (str ? strlen(str) : 0) - 1); } static void capacity_increase(QString *qstring, size_t len)