<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: fgets coredumps on nullbyte in textfile in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903585#M840002</link>
    <description>Hmm, maybe I'm too stupid to read that code sniplet, but shouldn't we check for fp!=NULL?&lt;BR /&gt; &lt;BR /&gt;if ((fp = fopen(szparsefile,"rb")) != NULL) &lt;BR /&gt; &lt;BR /&gt;Otherwise we don't read anything at all, do we?&lt;BR /&gt;</description>
    <pubDate>Tue, 24 May 2005 07:57:32 GMT</pubDate>
    <dc:creator>Dietmar Konermann</dc:creator>
    <dc:date>2005-05-24T07:57:32Z</dc:date>
    <item>
      <title>fgets coredumps on nullbyte in textfile</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903579#M839996</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I have some text files that only contains null bytes hex 00.( By error from an application)&lt;BR /&gt;&lt;BR /&gt;When fgets reads these files it core dumps.&lt;BR /&gt;buffer is allokated char of 32000&lt;BR /&gt;&lt;BR /&gt;char buffer[32000]&lt;BR /&gt;bufferlen = 32000&lt;BR /&gt;&lt;BR /&gt;The file is opened like this&lt;BR /&gt;if ((fp = fopen(szparsefile,"rb")) == NULL) &lt;BR /&gt;if(fgets(buffer,bufferlen,fp)==NULL) {&lt;BR /&gt;&lt;BR /&gt;HP-UX 11iv1&lt;BR /&gt;&lt;BR /&gt;Any ideas?&lt;BR /&gt;&lt;BR /&gt;rgds&lt;BR /&gt;Andreas</description>
      <pubDate>Tue, 24 May 2005 06:07:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903579#M839996</guid>
      <dc:creator>Andreas D. Skjervold</dc:creator>
      <dc:date>2005-05-24T06:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: fgets coredumps on nullbyte in textfile</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903580#M839997</link>
      <description>If its c/c++ check the code for null pointers, or improperly initialized variables.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Tue, 24 May 2005 06:38:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903580#M839997</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2005-05-24T06:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: fgets coredumps on nullbyte in textfile</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903581#M839998</link>
      <description>I've just compiled that code and tested it (though the filename should be quoted but I guess you know this).  It worked fine, so I don't know your problem.  Perhaps if you posted the whole code?  This is what I tested: -&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;&lt;BR /&gt;char buffer[32000];&lt;BR /&gt;int bufferlen;&lt;BR /&gt;FILE* fp;&lt;BR /&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;  if ((fp=fopen("testfile","rb")) == NULL){&lt;BR /&gt;    if (fgets(buffer,bufferlen,fp)==NULL){&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;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?&lt;BR /&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Tue, 24 May 2005 06:43:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903581#M839998</guid>
      <dc:creator>Simon Hargrave</dc:creator>
      <dc:date>2005-05-24T06:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: fgets coredumps on nullbyte in textfile</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903582#M839999</link>
      <description>Attached is the textfile with nullbytes</description>
      <pubDate>Tue, 24 May 2005 07:31:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903582#M839999</guid>
      <dc:creator>Andreas D. Skjervold</dc:creator>
      <dc:date>2005-05-24T07:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: fgets coredumps on nullbyte in textfile</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903583#M840000</link>
      <description>You are opening a file in binary mode ("rb" in open) then using fgets to read the contents. But fgets is designed for text-mode processing, looking (as it does) for end of line characters to break on (or the size arg, whichever happens first).</description>
      <pubDate>Tue, 24 May 2005 07:38:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903583#M840000</guid>
      <dc:creator>Stephen Keane</dc:creator>
      <dc:date>2005-05-24T07:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: fgets coredumps on nullbyte in textfile</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903584#M840001</link>
      <description>I agree with Simon - you probably should be using fread.  But, you should be able to use fgets - you'll get one returned line per null in the file - which would be the same of using fgetc instead.  But, if I needed to read a unknown length of nulls I think I'd put in a while loop to do fgetc until I didn't get any more null characters.  If you're skipping a block of known length of nulls - just fseek right around them if you know the byte offset in the file where they stop occuring.</description>
      <pubDate>Tue, 24 May 2005 07:40:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903584#M840001</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2005-05-24T07:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: fgets coredumps on nullbyte in textfile</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903585#M840002</link>
      <description>Hmm, maybe I'm too stupid to read that code sniplet, but shouldn't we check for fp!=NULL?&lt;BR /&gt; &lt;BR /&gt;if ((fp = fopen(szparsefile,"rb")) != NULL) &lt;BR /&gt; &lt;BR /&gt;Otherwise we don't read anything at all, do we?&lt;BR /&gt;</description>
      <pubDate>Tue, 24 May 2005 07:57:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903585#M840002</guid>
      <dc:creator>Dietmar Konermann</dc:creator>
      <dc:date>2005-05-24T07:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: fgets coredumps on nullbyte in textfile</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903586#M840003</link>
      <description>Good point on reading the file!  But it still works even when I recompiled my test with != (also put a printf in to prove it gets there).&lt;BR /&gt;&lt;BR /&gt;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!</description>
      <pubDate>Tue, 24 May 2005 08:12:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903586#M840003</guid>
      <dc:creator>Simon Hargrave</dc:creator>
      <dc:date>2005-05-24T08:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: fgets coredumps on nullbyte in textfile</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903587#M840004</link>
      <description>My point was that Andreas never calls fgets(), so the buffer never gets initialized or null-terminated.&lt;BR /&gt; &lt;BR /&gt;char buffer[32000]="";&lt;BR /&gt;&lt;BR /&gt;This could change a lot, I think.</description>
      <pubDate>Tue, 24 May 2005 08:22:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903587#M840004</guid>
      <dc:creator>Dietmar Konermann</dc:creator>
      <dc:date>2005-05-24T08:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: fgets coredumps on nullbyte in textfile</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903588#M840005</link>
      <description>Hi again.  &lt;BR /&gt;&lt;BR /&gt;We found the solution... Steven you had it at once. Uninitialized variables.. &lt;BR /&gt;&lt;BR /&gt;Thanks for your help. This forum is great.&lt;BR /&gt;&lt;BR /&gt;rgds&lt;BR /&gt;Andreas</description>
      <pubDate>Tue, 24 May 2005 08:31:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/fgets-coredumps-on-nullbyte-in-textfile/m-p/4903588#M840005</guid>
      <dc:creator>Andreas D. Skjervold</dc:creator>
      <dc:date>2005-05-24T08:31:15Z</dc:date>
    </item>
  </channel>
</rss>

