On Sun, Oct 9, 2016 at 1:06 PM, Gerhard Sittig <gerhard.sit...@gmx.net>
wrote:

> On Sat, Oct 08, 2016 at 16:14 -0400, Gaitan D'Antoni wrote:
> >
> > I just built libserialport on Windows 10 and while stepping through the
> > code I noticed a bug so I created the following patch:
> >
> > --- serialport.c        2016-10-08 13:41:23.269484000 -0400
> > +++ serialport1.c       2016-10-08 13:43:10.958994300 -0400
> > @@ -459,8 +459,8 @@
> >         char *escaped_port_name;
> >         COMSTAT status;
> >
> > -       /* Prefix port name with '\\.\' to work with ports above COM9. */
> > -       if (!(escaped_port_name = malloc(strlen(port->name) + 5)))
> > +       /* Prefix port name with '\\\\.\\' to work with ports above
> COM9. */
> > +       if (!(escaped_port_name = malloc(strlen(port->name) + 8)))
> >                 RETURN_ERROR(SP_ERR_MEM, "Escaped port name malloc
> failed");
> >         sprintf(escaped_port_name, "\\\\.\\%s", port->name);
>
> Can you expand on what's the issue?  I cannot see an obvious
> problem in the original source from looking at the patch.  And
> there is no comment / commit message that comes with your patch,
> explaining what the problem was and what the consequences might
> be, or how the changed version has improved.
>

There wasn't a specific issue or problem. I was stepping through the code,
chasing another problem and saw what I thought was a problem with too small
of a buffer being allocated to hold the string. In my haste I had forgotten
about the escaping.

>
> Consider that strlen("\\") == 1, and thus strlen("\\\\.\\") == 4.
> The first backslash escapes the subsequent one, the resulting
> string after resolving the escaped sequence is a single backslash
> (or three backslashes plus a dot in the second term).
>

Thanks for the explanation. At the time I wrote the patch I mistakenly
didn't consider the escaping.

>
> Also note the different quote characters.  The _source code_ uses
> double quotes, because that's how strings are phrased in the C
> programming language.  The _comment_ uses single quotes, which by
> convention denote "citations" or strict terms in the verbatim
> sense.
>
> So it's really \\.\ which needs to get prepended (that's a "UNC"
> style Windows path name).  It just happens to get phrased as
> "\\\\.\\" in the specific programming language.
>
>
> Did I miss something?
>

Nope, you didn't miss anything; I did. Thanks again for the explanation.

Gaitan

>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to