From 4501a8b88656aad1ad5001280d4d8a9c30a895a3 Mon Sep 17 00:00:00 2001 From: jub3i Date: Thu, 16 Jul 2015 11:23:00 +0200 Subject: [PATCH] better argument parsing --- src/robotjs.cc | 9 ++------- src/xdisplay.c | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/robotjs.cc b/src/robotjs.cc index eb1b75bb..b03d5742 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -2,7 +2,6 @@ #include #include #include -#include "string.h" #include "mouse.h" #include "deadbeef_rand.h" #include "keypress.h" @@ -690,13 +689,9 @@ NAN_METHOD(setXDisplayName) { NanScope(); - //Convert arg to c-string - //NOTE: surely better way to go from v8::String to char* ? - std::string name = - std::string(*v8::String::Utf8Value(args[0]->ToString())); - char *display_name = strdup(name.c_str()); + NanUtf8String name(args[0]); + setXDisplay(*name); - setXDisplay(display_name); NanReturnUndefined(); } diff --git a/src/xdisplay.c b/src/xdisplay.c index 6c51be45..ec57f6ad 100644 --- a/src/xdisplay.c +++ b/src/xdisplay.c @@ -49,6 +49,6 @@ char *getXDisplay(void) } void setXDisplay(char *name) { - displayName = name; + displayName = strdup(name); hasDisplayNameChanged = 1; }