2008/11/29 Bram Moolenaar wrote: > Dominique Pelle wrote: > >> Tests 58 and 59 fail when doing 'make test' with latest Vim-7.2.55 >> (huge version, tested on Linux). >> >> I tried older versions: >> >> - Vim-7.2.49 .... All tests pass >> - Vim-7.2.50 .... Tests 58 & 59 fail. >> >> Patch 7.2.50 introduces the regression:
[...snip...] > All the fwrite() calls have a "number of elements" argument of 1. When > fwrite succeeds it returns 1, when it fails it returns 0. So and-ing > all the 1 values together gives 1. If there is one zero the and-ed > value is zero. > > Perhaps frwrite() actually returns something different for you? Or > there is a problem with the conversion of size_t to int? You can change > the type of "fwv" to size_t and see if that makes a difference. Yes, you're right indeed, all the fwrite() here write only 1 element, so the patch looks OK at first sight. Yet, the patch does break tests 58 and 59. And reverting it definitely makes the tests pass. I added some printf(...) to debug, and I saw that at least in this line in spell.c... 8115 fwv &= fwrite(p, l, (size_t)1, fd); ... fwrite(...) returns 0 for me in some cases. It happens because second argument l is 0, meaning that it's trying to write 1 element of length 0, which is either useless or is a bug (I don't understand the code well enough to say). In any case, it's a bit of an odd case. Man page of fwrite(...) does not say what fwrite() should return when writing 1 element of size 0. I suspect it's not portable (like malloc(0)), and for me it returns 0 (interpreted as an error) and for you it returns 1. The attached patch makes the tests 58 and 59 succeed, by doing the frwrite(...) only if l > 0. But I'm not sure whether it should be considered as a workaround or whether it's the actual fix. Also, my patch adds only one "if (l > 0)" which is enough to make all test pass, but there are a few other places where the same may be necessary. -- Dominique --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
Index: spell.c =================================================================== RCS file: /cvsroot/vim/vim7/src/spell.c,v retrieving revision 1.117 diff -c -r1.117 spell.c *** spell.c 28 Nov 2008 20:27:23 -0000 1.117 --- spell.c 29 Nov 2008 15:29:55 -0000 *************** *** 8112,8118 **** p = rr == 1 ? ftp->ft_from : ftp->ft_to; l = (int)STRLEN(p); putc(l, fd); ! fwv &= fwrite(p, l, (size_t)1, fd); } } --- 8112,8119 ---- p = rr == 1 ? ftp->ft_from : ftp->ft_to; l = (int)STRLEN(p); putc(l, fd); ! if (l > 0) ! fwv &= fwrite(p, l, (size_t)1, fd); } }
