Possible error in CyBtldr_ReadLine()

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
user_1669321
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

Hi,

I'm trying to load a .cyacd2 file into my code by using cybtldr_parse.c.

Everything works fine until I reach the end of the file. At that point, CyBtldr_ReadLine() returns CYRET_ERR_EOF.

By looking at the condition for failing, I find it a bit hard to follow the logic.

if (NULL != dataFile && !feof(dataFile))

{

    if (NULL != fgets(buffer, CY_MAX_BUFFER_SIZE * 2, dataFile))

    {

        len = strlen(buffer);

        while (len > 0 && ('\n' == buffer[len - 1] || '\r' == buffer[len - 1]))

            --len;

    }

    else

        err = CYRET_ERR_EOF;

}

else

    err = CYRET_ERR_FILE;

It looks like the first if() is there because the code expects the last line to be incomplete. However, if the last line was complete, followed immediately by the EOF, then the first if() fails and returns CYRET_ERR_FILE.

Wouldn't the following be better?

if (NULL != dataFile)

{

    if (!feof(dataFile) && (NULL != fgets(buffer, CY_MAX_BUFFER_SIZE * 2, dataFile)))

    {

        len = strlen(buffer);

        while (len > 0 && ('\n' == buffer[len - 1] || '\r' == buffer[len - 1]))

            --len;

    }

    else

        err = CYRET_ERR_EOF;

}

else

    err = CYRET_ERR_FILE;

Thank you,

Fred

0 Likes
2 Replies
GeonaP_26
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 50 solutions authored

Which is the PSoC Creator version?

Please use the cybootloaderutils API files available as part of PSoC Creator 4.2 installation directory to bootload using .cyacd2 files (ie., C:\Program Files (x86)\Cypress\PSoC Creator\4.2\PSoC Creator\cybootloaderutils)

0 Likes

Hi GeonaM,

The file I'm using and the one in cybootloaderutils are the same (compared with KDiff3).

0 Likes