#421 N++ silently corrupts files

Don HO

As discussed in the 6.1.6 release thread in the forums, if you try to save a file to a disk which doesn't have enough space, N++ fails silently. An error message is required.

If you want to test it, I think the easiest way is to use TrueCrypt (http://www.truecrypt.org/) to create a small virtual disk.


  • Andreas Jonsson

    Andreas Jonsson - 2012-09-06
  • Don HO

    Don HO - 2012-09-07

    Thank you Andreas for the patch.

    I saw you use the return value (1 OK, otherwise KO) of Utf8_16_Write::fwrite() to determinate if there's save error.

    However, according the code of
    size_t Utf8_16_Write::fwrite(const void* p, size_t _size)
    The condtion you use is true only if the file to write is UTF16.
    When file is in other format, the c++ standard function fwrite will be called:
    c++ fwrite return the writen size in byte, so this condition (1 OK, otherwise KO) is not reliable.

    Could you check for that?

    Thank you,

    ps. the return value of Utf8_16_Write::fwrite is not consist IMO. It is necessary to modify it f we want to use its returned value.

  • Andreas Jonsson

    Andreas Jonsson - 2012-09-07

    The documentation is poorly worded:

    > The total number of elements successfully written is returned as a size_t object

    When you read this you're inclined to think that "elements" means "bytes" (the fact that the return type is size_t doesn't help either). If you look further up for the definition of "element" you see that this is not the case:

    > count - Number of elements, each one with a size of size bytes.

    Utf8_16_Write::fwrite() always attempts to write 1 element (of _size bytes) with UTF-8 files:

    > ret = ::fwrite(p, _size, 1, m_pFile);

    The return value will be 0 or 1. I've tested this with UTF-8 files. As far as I can see the return value of Utf8_16_Write::fwrite() is consistent.

  • Don HO

    Don HO - 2012-09-07


    Yes, you are right.
    Your patch will be included in the next release.


  • Don HO

    Don HO - 2012-09-07
    • assigned_to: nobody --> donho
    • priority: 5 --> 8
    • milestone: --> Next_release
  • Don HO

    Don HO - 2012-09-07


    FYI, your name is just added on page:

    Please let me know if you want to remove or modify it.

    Thank you for all your coding effort.

  • Don HO

    Don HO - 2012-09-16
    • status: open --> closed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks