Dominique Pellé <[email protected]> wrote:
> Bram Moolenaar <[email protected]> wrote:
>
> > Elimar Riesebieter wrote:
> >
> > > message_test fails on powerpc and i386 (32bit arch):
> > >
> > > message_test: message_test.c:170: void test_vim_snprintf(void): Assertion
> > > `n == 6' failed.
> > > Aborted
> > > make[1]: *** [Makefile:2242: run_message_test] Error 1
> > >
> > > Building on amd64 just runs fine.
> >
> > This should not be platform-dependent. In the build where it fails, can
> > you try:
> > :echo printf("-%06b-", 12)
> >
> > What does it show?
> >
> > Unfortunately assert() doesn't show what the actual value was. You
> > could add a printf() to show it.
>
> I can reproduce the assert failure after
> building vim-8.2.116 with -m32 to build
> for 32-bits x86 (after adding a few :i386 ubuntu
> packages).
>
> :echo printf("-%06b-", 12)
> -001100-
>
> The output looks as expected at least.
> But the test fails indeed:
>
> message_test: message_test.c:170: test_vim_snprintf: Assertion `n == 6'
> failed.
>
> Putting the following fprintf just before that assert...
>
> fprintf(stderr, "*** n=%d bsize=%d buf=[%s]\n", n, bsize, buf);
>
> It shows:
>
> *** n=63 bsize=0 buf=[]
>
> Value of n is completely wrong!?
I see why the test fails. The test at message_test.c:169 calls:
169 n = vim_snprintf(buf, bsize, fmt_06b, 12);
So the vararg 12 is an int (32-bits).
The vararg value corresponding to %b is found using
va_arg(ap, uvarnumber_T) at message.c:4540:
4533 else if (fmt_spec == 'b' || fmt_spec == 'B')
4534 {
4535 bin_arg =
4536 # if defined(FEAT_EVAL)
4537 tvs != NULL ?
4538
(uvarnumber_T)tv_nr(tvs, &arg_idx) :
4539 # endif
!!4540 va_arg(ap, uvarnumber_T);
4541 if (bin_arg != 0)
4542 arg_sign = 1;
4543 }
There is a type mismatch between value 12 (an int) and expected
type uvarnumber_T which is a uint64_t (actually the type can depend
on platform and on whether FEAT_NUM64 is defined).
Adding a cast in the test fixes it.
See attached patch fix-message-test.patch.
Regards
Dominique
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/CAON-T_jW3tkFOju%2BOU45%3DNkq8E%2BPXsrzUaVLDA6xj8OO_UO_GA%40mail.gmail.com.
diff --git a/src/message_test.c b/src/message_test.c
index 38e52c5f8..3397a9cb4 100644
--- a/src/message_test.c
+++ b/src/message_test.c
@@ -166,7 +166,7 @@ test_vim_snprintf(void)
assert(bsize == 0 || STRNCMP(buf, "deadbeef", bsize_int) == 0);
assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
- n = vim_snprintf(buf, bsize, fmt_06b, 12);
+ n = vim_snprintf(buf, bsize, fmt_06b, (uvarnumber_T)12);
assert(n == 6);
assert(bsize == 0 || STRNCMP(buf, "001100", bsize_int) == 0);
assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');