This is the mail archive of the ecos-bugs@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug 1000800] Diagnostics API does not include diag_vsnprintf


Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1000800

--- Comment #8 from Sergei Gavrikov <sergei.gavrikov@gmail.com> 2010-11-20 22:48:44 GMT ---
Hm. Puzzle. Such a test will pass without an assertion fail if I compile it
using host GCC.

#include <stdio.h>
#include <assert.h>
#include <string.h>
#define STRING10 "1234567890"
int main(void) {
    char x[100];
    int ret=0;
    ret+=snprintf(NULL, 0, "%s", STRING10);
    ret+=snprintf(x, 0, "%s", STRING10);
    ret+=snprintf(x, 10, "%s", STRING10);
    ret+=snprintf(x, 10-1, "%s", STRING10);
    ret+=snprintf(x, 10+1, "%s", STRING10);
    assert(ret==10+10+10+10+10);
    return (0);
}

% for arg in -std=c99 -std=c89 -std=gnu99 -D_BSD_SOURCE
> do
> cc $arg test.c && ./a.out
> done
%

% man snprintf ;# keyphrase: which would have been written...

But, diag_snprintf() won't pass the same sequences. I should write something
like the below

// N-room tests
ret = diag_snprintf(x, 0, "%s", "1234567890");
CYG_TEST_PASS_FAIL(0==my_strlen(x), "n=0 test");
CYG_TEST_PASS_FAIL(ret==0, "n=0 test return code");

ret = diag_snprintf(x, 10, "%s", "1234567890");
CYG_TEST_PASS_FAIL(0==my_strcmp(x, "123456789"), "n=L test");
CYG_TEST_PASS_FAIL(ret==9, "n=L test return code");

ret = diag_snprintf(x, 10-1, "%s", "1234567890");
CYG_TEST_PASS_FAIL(0==my_strcmp(x,"12345678"), "n=L-1 test");
CYG_TEST_PASS_FAIL(ret==8, "n=L-1 test return code");

ret = diag_snprintf(x, 10+1, "%s", "1234567890");
CYG_TEST_PASS_FAIL(0==my_strcmp(x,"1234567890"), "n=L+1 test");
CYG_TEST_PASS_FAIL(ret==10, "n=L+1 test return code");

I  dislike it. Comments?

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]