Hello Mr. McMackins, hello Mr. Viste,

I found the bad code. While your example works, if I change it to use
calloc (which is what my code is using at the particular failure point),
then it fails. Looks like calloc is doing something funny.

Actually, I just found that both malloc( ) and calloc( ) do not work for the purpose, and we _do_ need to use something like halloc( ).

I double-checked the compiler output (using `wdis test.o') for the malloc( ) call under the huge model, and found that it actually clips the size to a `size_t', and `size_t' is a 16-bit integer type even for the huge model. I.e. malloc(81920) only allocates 16384 bytes.

        #include <stdlib.h>

        int main(void)
        {
                char __huge *buf = malloc(81920ul);
                unsigned long i;
                for (i = 0; i < 81920ul; ++i)
                        buf[i] = 0xf6;  /* crash */
                free(buf);
                return 0;
        }

halloc( ) however will correctly allocate a buffer that spans multiple segments.

Thank you!

--
https://github.com/tkchia

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

Reply via email to