OpenEtherCATsociety / SOES

Simple Open Source EtherCAT Slave
Other
566 stars 247 forks source link

FOE_fwrite is unable to detect a failure if write_function fails to write on last data. #124

Closed fsugai closed 1 year ago

fsugai commented 1 year ago

I think there is a problem that FOE_fwrite() cannot detect failure if write_function() failed writing on last data.

The following code checks if FOE_fwrite() can write the entire data correctly. https://github.com/OpenEtherCATsociety/SOES/blob/fc72fbeeecc10d53c9c0655c88d43214c4ef0759/soes/esc_foe.c#L473-L477

However, at line 165, ncopied is incremented even if foe_file->write_function() returns a failure flag. This only matters if the last data write fails. https://github.com/OpenEtherCATsociety/SOES/blob/fc72fbeeecc10d53c9c0655c88d43214c4ef0759/soes/esc_foe.c#L154-L166

I suggest the following fixes.

       if(failed)
       {
          DPRINT("Failed FOE_fwite ncopied=%d\n", ncopied);
       }
       else
       {
          ncopied++;
       }
nakarlsson commented 1 year ago

It make sense, can you provide a pull request?

fsugai commented 1 year ago

Thanks for the checking. I sent a PR #126.