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

Frediano Ziglio fziglio at redhat.com
Thu Feb 22 08:14:45 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>

This was already acked.
It would be kind if you report it so other people don't spend time on the
review again.

Frediano

> ---
>  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 894f86c..acec001 100644
> --- a/src/spice-streaming-agent.cpp
> +++ b/src/spice-streaming-agent.cpp
> @@ -354,12 +354,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) {
> @@ -443,7 +444,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);


More information about the Spice-devel mailing list