- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- NULL problem in HP server
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2009 02:53 AM
тАО02-25-2009 02:53 AM
I am facing a problem in a C code which is working perfectly in AIX platform, but in HP it fails. In HP server, when i call a function in c using sample(NULL) it fails but when i call the same using sample(""), it works. This behaviour is looking strange in HP boxes. Can it be fixed say by caling that function using sample(NULL)? Can anybody suggest a solution?
The version of HP is B.11.11 U 9000/800.
Thx for your help inadvance.
Solved! Go to Solution.
- Tags:
- NULL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2009 03:02 AM
тАО02-25-2009 03:02 AM
Re: NULL problem in HP server
#include
int main()
{
char **variable=NULL;
printf("Starting\n");
fflush(stdout);
while(*variable)
{
printf("Inside while\n");
fflush(stdout);
break;
}
printf("Ending\n");
fflush(stdout);
}
The output is:
Starting
Memory fault(coredump)
Can anybody make it work on a HP machine?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2009 03:09 AM
тАО02-25-2009 03:09 AM
Re: NULL problem in HP server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2009 03:27 AM
тАО02-25-2009 03:27 AM
Re: NULL problem in HP server
An empty string ("") is a pointer to a valid memory location which only contains the string terminator character, '\0'.
These are two different things.
As we don't have access to the source code of your function, I cannot see what is wrong. But I guess that the function does not properly check its input for NULLness: it might make *some* checks that are adequate for AIX, but not good for portable C code.
From a document "Recommended C Style and Coding Standards":
http://www.psgd.org/paul/docs/cstyle/cstyle.htm
Chapter 16, "Portability":
[...]
# On some machines, the null character pointer ((char *)0) is treated the same way as a pointer to a null string. Do not depend on this.
[...]
Obviously, the AIX programmer that wrote the code has not read this document.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2009 03:33 AM
тАО02-25-2009 03:33 AM
Re: NULL problem in HP server
char **variable = NULL;
while (*variable) {
So really, you've written while (*NULL). NULL should not be dereferenced. If you set variable to "", that still isn't exactly right (since "" is a constant array of char, not a char **... this is just the empty string. You could set *variable to "", but first you'd need to allocate memory for a char * to do that).
I would suspect the problem in the real code may be similar -- if the sample() function expects a valid string -- calling with NULL means the function will attempt to check the string length of an invalid pointer. Boom. Calling with "" on the other hand _is_ a valid [empty] string, hence why it works.
The obvious fix if you truly want to call sample() at times with no string is to have a check at the start of sample() for if (input == NULL ) { return; // Or do whatever is reasonable here, but don't deref! } .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2009 03:34 AM
тАО02-25-2009 03:34 AM
Re: NULL problem in HP server
Thanks for your quick and valuable response. i ve already given a sample code which works on a AIX machine but not in HP. That is a very simple version of our huge application. The actual application has 100k such codes. So we are in a state to find out a solution other than code change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2009 03:39 AM
тАО02-25-2009 03:39 AM
Re: NULL problem in HP server
Thanks for your reply.
Wats the compiler version using? we haven't used any options while compiling. we are using GCC as compiler and its version is "gcc version 4.1.2". Since GCC is a freeware we are using this compiler.
Wats the difference in ur version of server and ours? Can we make it work in our machine with any configuration settings change?
- Tags:
- gcc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2009 03:44 AM
тАО02-25-2009 03:44 AM
Re: NULL problem in HP server
Thanks for your inputs
We cant afford to make such code changes in our application since it has around 100K LOC. :(
Need to fix without code changes. Thats the sad thing here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2009 03:45 AM
тАО02-25-2009 03:45 AM
Re: NULL problem in HP server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2009 05:17 AM
тАО02-25-2009 05:17 AM
Re: NULL problem in HP server
That said, this is not what I'd call a good idea and you've got some risk here. If all this thing ever does is treat NULL like a string, attempt to look for the '\0' terminator... then you're probably okay [since I believe you get to read zeros from the Zero page when NULL deref is disabled, and 0 looks like '\0' if my memory serves]. Hence a string operation on NULL in this model will see an "empty" string right off and you'll survive. If your code tries to do anything later like store something to that string buffer, you're still hosed. At least since it runs on AIX (and has for a while), the odds are it doesn't do that.
So "-Z" will probably get you going -- but I'd still fix that source in the future to have more clean portability.