Operating System - HP-UX
1748283 Members
3703 Online
108761 Solutions
New Discussion юеВ

vsnprintf is not working properly on HP-UX Itanium

 
SOLVED
Go to solution
girishgawali
Occasional Advisor

vsnprintf is not working properly on HP-UX Itanium

Below is code snippet:

void test_emptyBuffer()
{
const o_4b stringLengthWithoutNull = 4;
const o_4b bufferSize = 0;
char buf[2];
clearBuffer(buf, 2);

o_4b returnValue = vs_snprintf(buf, (size_t) bufferSize, "%s", "emil");
cout<< "returnValue is:"<< returnValue < cout<< "buf is:"<< buf< string resultString = string(buf);
cout<< "resultString is:"<< resultString< string expectedString = string("*");
cout<< "expectedString is:"<< expectedString< TS_ASSERT_EQUAL_STRINGS(resultString, expectedString, "unmodified buffer");
TS_ASSERT_EQUALS(returnValue, stringLengthWithoutNull, "return value");
}


vs_snprintf is Wrapper for the functions vsnprintf

o_4b vs_snprintf(char *buf, size_t count, char* format, ...)
{

va_list argp;
va_start(argp, format);
o_4b result = 0;

result = vsnprintf(buf, count, format, argp);
va_end(argp);

if (result < 0)
{
va_start(argp, format);
result = vs_scprintfInternal(format, argp);
va_end(argp);
}

return result;

}


After running this program:

even if the bufferSize is 0 (means count is 0) ,vs_snprintf(ultimately vsnprintf) function write "emil" string into the buf

Why is it so?
It should not write anything into the buf as we are specifying bufferSize as zero

fyi ...
Below are the more values
returnValue is:4
resultString is:emil
expectedString is:*

12 REPLIES 12
Steven E. Protter
Exalted Contributor

Re: vsnprintf is not working properly on HP-UX Itanium

Shalom,

Perhaps grace us with your OS version.

You might try a bi-annual patch update or search the http://itrc.hp.com batch database for a patch that applies to the command you are using.

You might try updating your development libraries.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: vsnprintf is not working properly on HP-UX Itanium

>even if the bufferSize is 0 (means count is 0), vsnprintf function writes "emil" string into the buf
>It should not write anything into the buf as we are specifying bufferSize as zero

I thought I've seen a bug where it writes one byte but not more?

As SEP said, you need to mention the OS version. vsnprintf(3) will not work correctly unless you are on 11.31 and you ask for Unix 2003 branding. But writing to the buffer with length zero, shouldn't be one of the accepted results.
Dennis Handly
Acclaimed Contributor

Re: vsnprintf is not working properly on HP-UX Itanium

I went to enter your test case and found I already had a test case with that name and for the same error. ;-)

This was discussed in:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1320687

I'm not sure if there is a bug report for this for 11.23? It works for 11.31.
girishgawali
Occasional Advisor

Re: vsnprintf is not working properly on HP-UX Itanium

Thanks a lot Guys for your reply.

about OS version :
the o/p of uname -a is
HP-UX hermes B.11.23 U ia64 2917453674 unlimited-user license

It means os version is 11.23

@Dennis
> I thought I've seen a bug where it writes one byte but not more?

In my case case it is writing more than one byte

>I'm not sure if there is a bug report for this for 11.23?
Can you please confirm me whether this is a known bug for 11.23?
So that next path is clear

As you said,vsnprintf will not work correctly unless you are on 11.31 and the os version which I am working on is 11.23.

So the question is how should I upgrade this os version?(ofcourse by applying patch)


@SEP:
>You might try a bi-annual patch update
where is this patch located(exact location)?

Before doing this,is there any alternative function available for vsnprintf function?
So that I can use it in my case

Thanks
Dennis Handly
Acclaimed Contributor

Re: vsnprintf is not working properly on HP-UX Itanium

>Can you please confirm me whether this is a known bug for 11.23?

I'm not sure if it was ever reported. Or if it was and only fixed on 11.31?

>So the question is how should I upgrade this OS version? (of course by applying patch)

11.31 is a whole NEW OS version. No patching possible. (Unless you contact the Response Center and you report the problem.)

>is there any alternative function available for vsnprintf function?

Not really. Unless you check for length 0 and allocate/then free some "large" buffer.
girishgawali
Occasional Advisor

Re: vsnprintf is not working properly on HP-UX Itanium

>Unless you check for length 0 and allocate/then free some "large" buffer.

I am not getting what you are trying to say.
Can you please explain it more?
(Does this resolve the problem?)
Steven E. Protter
Exalted Contributor

Re: vsnprintf is not working properly on HP-UX Itanium

Shalom,

In reply to your @SEP

http://www11.itrc.hp.com/service/patch/mainPage.do

That is the patch database. There are links to the bi-annual patch sets on that site.

The best download method if possible is ftp script.

Also note that the site is very good at building larger patch sets that include needed dependent patches.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor

Re: vsnprintf is not working properly on HP-UX Itanium

Shalom again,

Another thing to think about on the patching front is SWA.

http://software.hp.com/portal/swdepot/displayProductInfo.do?productNumber=B6834AA

This is a very helpful tool in building patch sets.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor
Solution

Re: vsnprintf is not working properly on HP-UX Itanium

>I am not getting what you are trying to say. Can you please explain it more?

char *p = buf;
char big_buf[1024];
if (count == 0) // workaround
p = big_buf;

result = vsnprintf(p, count, format, argp);
va_end(argp);

>Does this resolve the problem?

No, it works around the problem, a kludge.