- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- fgets coredumps on nullbyte in textfile
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
Forums
Discussions
Discussions
Discussions
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
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
05-23-2005 11:07 PM
05-23-2005 11:07 PM
I have some text files that only contains null bytes hex 00.( By error from an application)
When fgets reads these files it core dumps.
buffer is allokated char of 32000
char buffer[32000]
bufferlen = 32000
The file is opened like this
if ((fp = fopen(szparsefile,"rb")) == NULL)
if(fgets(buffer,bufferlen,fp)==NULL) {
HP-UX 11iv1
Any ideas?
rgds
Andreas
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2005 11:38 PM
05-23-2005 11:38 PM
SolutionSEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2005 11:43 PM
05-23-2005 11:43 PM
Re: fgets coredumps on nullbyte in textfile
#include
char buffer[32000];
int bufferlen;
FILE* fp;
main()
{
if ((fp=fopen("testfile","rb")) == NULL){
if (fgets(buffer,bufferlen,fp)==NULL){
}
}
}
However shouldn't you really be using fread? fgets will give you a null-terminated buffer, and since your file is full of nulls, how will you know where your read buffer ends?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2005 12:31 AM
05-24-2005 12:31 AM
Re: fgets coredumps on nullbyte in textfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2005 12:38 AM
05-24-2005 12:38 AM
Re: fgets coredumps on nullbyte in textfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2005 12:40 AM
05-24-2005 12:40 AM
Re: fgets coredumps on nullbyte in textfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2005 12:57 AM
05-24-2005 12:57 AM
Re: fgets coredumps on nullbyte in textfile
if ((fp = fopen(szparsefile,"rb")) != NULL)
Otherwise we don't read anything at all, do we?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2005 01:12 AM
05-24-2005 01:12 AM
Re: fgets coredumps on nullbyte in textfile
But Andreas, when I asked for you to send the file, I meant the source code, not the file full of nulls ;) That's easy for us to reproduce!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2005 01:22 AM
05-24-2005 01:22 AM
Re: fgets coredumps on nullbyte in textfile
char buffer[32000]="";
This could change a lot, I think.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2005 01:31 AM
05-24-2005 01:31 AM
Re: fgets coredumps on nullbyte in textfile
We found the solution... Steven you had it at once. Uninitialized variables..
Thanks for your help. This forum is great.
rgds
Andreas