[Spice-devel] [PATCH spice-server 04/33] Avoids %m in formatting for Windows

Frediano Ziglio fziglio at redhat.com
Sat Dec 22 15:26:39 UTC 2018


> 
> Hi
> 
> On Sat, Dec 22, 2018 at 5:49 PM Frediano Ziglio <fziglio at redhat.com> wrote:
> >
> > >
> > > On Fri, Dec 21, 2018 at 4:03 PM Frediano Ziglio <fziglio at redhat.com>
> > > wrote:
> > > >
> > > > Not supported.
> > > >
> > > > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > > > --
> > > > TODO find a better solution
> > >
> > > May be unnecessary with __USE_MINGW_ANSI_STDIO (to check)
> > >
> >
> > Not sure but this surely would limit the compiler(s?) to MingW only.
> 
> Probably, I don't care much about other compilers. I don't think you
> can compile qemu for windows without mingw either, fwiw
> 

SPICE server is not Qemu, people could use for different purpose like
something like Xspice for Windows and having support for Visual
Studio could be helpful. Also because the differences are really small.

> In any case, if you adopt this patch, it should run the same code
> instead of 2 code paths.
> 

Yes, agree this patch is ugly (forgot about the TODO) and code path
should be single. Maybe use some more "standard" strtok or something
similar (g_strsplit_set?).
Maybe copy the entire string? Not supposed to be big and calling
malloc/free for every piece is not surely quicker.

> >
> > >
> > > > ---
> > > >  server/reds.c | 7 +++++++
> > > >  1 file changed, 7 insertions(+)
> > > >
> > > > diff --git a/server/reds.c b/server/reds.c
> > > > index aa3f8ca7..2874bd4c 100644
> > > > --- a/server/reds.c
> > > > +++ b/server/reds.c
> > > > @@ -3582,7 +3582,14 @@ static const char* parse_next_video_codec(const
> > > > char
> > > > *codecs, char **encoder,
> > > >      }
> > > >      int n;
> > > >      *encoder = *codec = NULL;
> > > > +#ifndef _WIN32
> > > >      if (sscanf(codecs, "%m[0-9a-zA-Z_]:%m[0-9a-zA-Z_]%n", encoder,
> > > >      codec,
> > > >      &n) == 2) {
> > > > +#else
> > > > +    char encoder_buf[130], codec_buf[130];
> > > > +    if (sscanf(codecs, "%128[0-9a-zA-Z_]:%128[0-9a-zA-Z_]%n",
> > > > encoder_buf,
> > > > codec_buf, &n) == 2) {
> > > > +        *encoder = strdup(encoder_buf);
> > > > +        *codec = strdup(codec_buf);
> > > > +#endif
> > > >          // this avoids accepting "encoder:codec" followed by garbage
> > > >          like
> > > >          "$%*"
> > > >          if (codecs[n] != ';' && codecs[n] != '\0') {
> > > >              free(*codec);
> >


More information about the Spice-devel mailing list