[Spice-devel] [PATCH 04/17] Do not create std::string for constants

Christophe de Dinechin christophe at dinechin.org
Fri Feb 16 16:15:34 UTC 2018


From: Christophe de Dinechin <dinechin at redhat.com>

As per e-mail discussions (https://patchwork.freedesktop.org/patch/200629/),
using std::string for C-style string constants is against C++ good practices,
see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rstr-zstring for reference.

Signed-off-by: Christophe de Dinechin <dinechin at redhat.com>
---
 src/spice-streaming-agent.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
index b5c7e24..646d15b 100644
--- a/src/spice-streaming-agent.cpp
+++ b/src/spice-streaming-agent.cpp
@@ -315,12 +315,13 @@ static void cursor_changes(Display *display, int event_base)
 }
 
 static void
-do_capture(const std::string &streamport, FILE *f_log)
+do_capture(const char *streamport, FILE *f_log)
 {
-    streamfd = open(streamport.c_str(), O_RDWR);
+    streamfd = open(streamport, O_RDWR);
     if (streamfd < 0)
         throw std::runtime_error("failed to open the streaming device (" +
-                                 streamport + "): " + strerror(errno));
+                                 std::string(streamport) + "): "
+                                 + strerror(errno));
 
     unsigned int frame_count = 0;
     while (!quit_requested) {
@@ -404,7 +405,7 @@ done:
 
 int main(int argc, char* argv[])
 {
-    std::string streamport = "/dev/virtio-ports/com.redhat.stream.0";
+    const char *streamport = "/dev/virtio-ports/com.redhat.stream.0";
     char opt;
     const char *log_filename = NULL;
     int logmask = LOG_UPTO(LOG_WARNING);
-- 
2.13.5 (Apple Git-94)



More information about the Spice-devel mailing list