This is the mail archive of the mailing list for the eCos project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ECOS] Problem in cyg_io_compare?

"Gary D. Thomas" <> writes:

> On Mon, 2003-07-28 at 07:07, David N. Welton wrote:

> > Does this patch look out of place?

> Actually, it would be preferable to discuss such things on
> ecos-patches or ecos-devel.

Oh, sorry.  Switching to that, but please CC replies to me, because
I'm not subscribed.  Patched code in question included at the end of
the email for anyone not on -discuss.

> > Without it, setting *ptr to n1 is just going to leave *ptr hanging
> > off the end of the 'real' n1, according to my reading of the code.
> > This fix seems to make things work for me (i.e. the name parameter
> > to my device's lookup function actually contains something valid).

> It's not clear why you think there is an error here.  The code looks
> right to me and the only time that *ptr could point off the end of
> the string would be if n1 pointed to a string which matched 100% n2.

Maybe I am using eCos incorrectly then, because that's what happens:

I have:

		   NULL, /* Not dependant on other devices. */
		   (void *)NULL); /* No private information.  */

and then:

    if (cyg_io_lookup("/dev/fd", &fh) != ENOERR) {

Maybe that's not the best way to do things?

If the two strings are equal, cyg_io_compare returns true, but the
'name' pointer in my lookup function is garbage because *ptr is set
off the end of n1 in the compare function.  This patch fixes that by
storing the original location of 'n1' to later put in '*ptr'.

I think that in any case, returning a bogus address should be avoided
in one way or another.

Thanks for your time,
David N. Welton
Free Software:
   Apache Tcl:

static bool
cyg_io_compare(const char *n1, const char *n2, const char **ptr)
    char *tmp;
    tmp = n1;
    while (*tmp && *n2) {
        if (*(tmp++) != *(n2++)) {
            return false;
    if (*tmp) {
        // See if the devtab name is is a substring
        if (*(n2 - 1) == '/') {
            *ptr = n1;
            return true;
    if (*tmp || *n2) {
        return false;
    *ptr = n1;
    return true;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]