[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 04/14] qmp: qstring: Handle NULL strings
From: |
Peter Crosthwaite |
Subject: |
[Qemu-devel] [PATCH v2 04/14] qmp: qstring: Handle NULL strings |
Date: |
Thu, 14 Aug 2014 22:31:32 -0700 |
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.
Signed-off-by: Peter Crosthwaite <address@hidden>
---
qobject/qstring.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
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)
--
2.0.1.1.gfbfc394
- [Qemu-devel] [PATCH v2 00/14] GPIO/IRQ QOMification: Phase 2 - Getting rid of SYSBUS IRQs, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 01/14] qdev: gpio: Don't allow name share between I and O, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 02/14] qdev: gpio: Register GPIO inputs as child objects, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 03/14] qdev: gpio: Register GPIO outputs as QOM links, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 04/14] qmp: qstring: Handle NULL strings,
Peter Crosthwaite <=
- [Qemu-devel] [PATCH v2 05/14] qom: Allow clearing of a Link property, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 06/14] qom: Demote already-has-a-parent to a regular error, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 07/14] qdev: gpio: Re-impement qdev_connect_gpio QOM style, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 08/14] qdev: gpio: Add API for intercepting a GPIO, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 09/14] qtest/irq: Rework IRQ interception, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 10/14] irq: Remove qemu_irq_intercept_out, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 11/14] qdev: gpio: delete NamedGPIOList::out, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 12/14] qdev: gpio: Remove qdev_init_gpio_out x1 restriction, Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 13/14] qdev: gpio: Define qdev_pass_gpios(), Peter Crosthwaite, 2014/08/15
- [Qemu-devel] [PATCH v2 14/14] sysbus: Use TYPE_DEVICE GPIO functionality, Peter Crosthwaite, 2014/08/15