<?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: invalid pointer address in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482956#M639975</link>
    <description>I would still upgrade to a later version of ANSI/C but there is a B.11.11.04 ANSI/C patch (PHSS_26792) which addresses a memset problem that looks exactly like yours.&lt;BR /&gt;</description>
    <pubDate>Fri, 11 Feb 2005 11:13:31 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2005-02-11T11:13:31Z</dc:date>
    <item>
      <title>invalid pointer address</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482950#M639969</link>
      <description>Hello together,&lt;BR /&gt;&lt;BR /&gt;the program below shows a behavior i do not understand. When compiled with the HX-UX11 c-comiler ( version B.11.11.04 ) v2.p in function test_it0 points to an invalid adress and an attempt to write to this pointer causes the program to exit with a core dump.&lt;BR /&gt;Output after compiling with HP c-compiler:&lt;BR /&gt;1. ffffff78&lt;BR /&gt;1. 7eff3358&lt;BR /&gt;&lt;BR /&gt;When compiled with the gcc compiler the functions test_it0 and&lt;BR /&gt;test_it1 are working in the same ( correct ) manner.&lt;BR /&gt;Output when compiled with gcc:&lt;BR /&gt;1. 800003fffeff3730&lt;BR /&gt;1. 800003fffeff3730&lt;BR /&gt;&lt;BR /&gt;After moving the memset command just before the printff command it also works ok with both compilers. Even if you comment out the line "static char BLANK_VTRNR[2] = " ";" both functions are working.&lt;BR /&gt;&lt;BR /&gt;Unfortunately i found this Problem while searching for the reason of a program crash in a larger project. Thus i cant change to another compiler and the described work araunds ( comment out af the declaration, moving the memset command ) does not lead to the same effect as in this small program.&lt;BR /&gt;&lt;BR /&gt;Any comment is rather appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks in Advance.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;---------/snip --------------------&lt;BR /&gt;extern void *memset(void *, int, unsigned long);&lt;BR /&gt;&lt;BR /&gt;static char BLANK_VTRNR[2] = " ";&lt;BR /&gt;&lt;BR /&gt;struct s1{ char c[ 81 ]; };&lt;BR /&gt;struct s2{ void *p; };&lt;BR /&gt;&lt;BR /&gt;void test_it0( void )&lt;BR /&gt;{&lt;BR /&gt;  struct s1 v1;&lt;BR /&gt;  memset( (void*)&amp;amp;v1, 0, sizeof( struct s1 ) );&lt;BR /&gt;  struct s2 v2 = { &amp;amp;v1.c };&lt;BR /&gt;  printf( "1. %lx\n", v2.p );&lt;BR /&gt;/*&lt;BR /&gt;  strcpy( v2.p, "Hallo ich schreibe mal was rein.." );&lt;BR /&gt;  printf( "%s\n", v2.p );&lt;BR /&gt;*/&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void test_it1(void)&lt;BR /&gt;{&lt;BR /&gt;  struct s1 v1;&lt;BR /&gt;  struct s2 v2=  { &amp;amp;v1.c };&lt;BR /&gt;  printf( "1. %lx\n", v2.p );&lt;BR /&gt;/*&lt;BR /&gt;  strcpy( v2.p, "Hallo ich schreibe mal was rein.." );&lt;BR /&gt;  printf( "%s\n", v2.p );&lt;BR /&gt;*/&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void main ()&lt;BR /&gt;{&lt;BR /&gt;  test_it0();&lt;BR /&gt;  test_it1();&lt;BR /&gt;}&lt;BR /&gt;------------/snap/---------------&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Feb 2005 09:07:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482950#M639969</guid>
      <dc:creator>FrankAtWork</dc:creator>
      <dc:date>2005-02-10T09:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: invalid pointer address</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482951#M639970</link>
      <description>The one thing I notice is that you are not quite playing by the rules -- if this is C as opposed to C++. In C, variable declarations are only allowed at the top of a given block before any executable statements. Your memset() comes between variable declarations in one of your functions. C++ relaxes this rule and variable declarations can go anywhere with a block. Now, a C compiler should catch this but ...</description>
      <pubDate>Thu, 10 Feb 2005 10:36:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482951#M639970</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-02-10T10:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: invalid pointer address</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482952#M639971</link>
      <description>I don't see what relevnce the declaration &lt;BR /&gt;&lt;BR /&gt;static char BLANK_VTRNR[2] = " ";&lt;BR /&gt;&lt;BR /&gt;has to the problem.&lt;BR /&gt;&lt;BR /&gt;For printing the address of a pointer, I would normally use %p not %lx.&lt;BR /&gt;&lt;BR /&gt;printf( "1. %p\n", v2.p );&lt;BR /&gt;&lt;BR /&gt;Also, prototype of memset should be&lt;BR /&gt;&lt;BR /&gt;void *memset(void *s, int c, size_t n)&lt;BR /&gt;&lt;BR /&gt;In test_it1() you are printing the contents of a (void *) pointing to an address in uninitialised memory. I suspect the gcc compiler is initialising the memory for you which is why you aren't getting the error with the gcc compiler.&lt;BR /&gt;&lt;BR /&gt;Thus your program should read:&lt;BR /&gt;&lt;BR /&gt;extern void *memset(void *s, int c, size_t n);&lt;BR /&gt;&lt;BR /&gt;struct s1{ char c[ 81 ]; };&lt;BR /&gt;struct s2{ void *p; };&lt;BR /&gt;&lt;BR /&gt;void test_it0( void )&lt;BR /&gt;{&lt;BR /&gt;    struct s1 v1;&lt;BR /&gt;    memset( (void*)&amp;amp;v1, 0, sizeof( struct s1 ) );&lt;BR /&gt;    struct s2 v2 = { &amp;amp;v1.c };&lt;BR /&gt;    printf( "1. %p\n", v2.p );&lt;BR /&gt;    strcpy( v2.p, "Hallo ich schreibe mal was rein.." );&lt;BR /&gt;    printf( "%s\n", (char *) v2.p );&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void test_it1(void)&lt;BR /&gt;{&lt;BR /&gt;    struct s1 v1;&lt;BR /&gt;    memset( (void*)&amp;amp;v1, 0, sizeof( struct s1 ) );&lt;BR /&gt;    struct s2 v2= { &amp;amp;v1.c };&lt;BR /&gt;    printf( "1. %p\n", v2.p );&lt;BR /&gt;    strcpy( v2.p, "Hallo ich schreibe mal was rein.." );&lt;BR /&gt;    printf( "%s\n", (char *) v2.p );&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;int main ()&lt;BR /&gt;{&lt;BR /&gt;    test_it0();&lt;BR /&gt;    test_it1();&lt;BR /&gt;&lt;BR /&gt;    return(0);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Feb 2005 10:42:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482952#M639971</guid>
      <dc:creator>Stephen Keane</dc:creator>
      <dc:date>2005-02-10T10:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: invalid pointer address</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482953#M639972</link>
      <description>To explain how i came to this program:&lt;BR /&gt;I am working on a larger project, which exits with a core dump. The reason for this is that there ist a strcpy instruction to a misleading pointer.&lt;BR /&gt;After I found where the pointer gets its invalid adress, i copied this part to a new programm and included al the projects includes. As the error still occures i startet to remove all includes and definitions until i found the definition of "static char BLANK_VTRNR[2] = " ";"&lt;BR /&gt;changed the program behavior. Because i do not have any idea why this happened I asked for help here.&lt;BR /&gt;After I changed the Programm in the way you suggested the same error&lt;BR /&gt;appears:&lt;BR /&gt; ./test_it   &lt;BR /&gt;1. ffffff78&lt;BR /&gt;1. 7eff3328&lt;BR /&gt;&lt;BR /&gt;----------/snip/--------------&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;&lt;BR /&gt;static char BLANK_VTRNR[2] = " "; &lt;BR /&gt;&lt;BR /&gt;struct s1{ char c[ 81 ]; };&lt;BR /&gt;struct s2{ void *p; }; &lt;BR /&gt;&lt;BR /&gt;void test_it0( void )&lt;BR /&gt;{&lt;BR /&gt;  struct s1 v1;&lt;BR /&gt;  memset( (void*)&amp;amp;v1, 0, sizeof( struct s1 ) );&lt;BR /&gt;  struct s2 v2 = { &amp;amp;v1.c };&lt;BR /&gt;  printf( "1. %p\n", v2.p );&lt;BR /&gt;/*&lt;BR /&gt;  strcpy( v2.p, "Hallo ich schreibe mal was rein.." );&lt;BR /&gt;  printf( "%s\n", v2.p );&lt;BR /&gt;*/&lt;BR /&gt;} &lt;BR /&gt;&lt;BR /&gt;void test_it1(void)&lt;BR /&gt;{&lt;BR /&gt;  struct s1 v1;&lt;BR /&gt;  struct s2 v2=  { &amp;amp;v1.c };&lt;BR /&gt;  printf( "1. %p\n", v2.p );&lt;BR /&gt;/*&lt;BR /&gt;  strcpy( v2.p, "Hallo ich schreibe mal was rein.." );&lt;BR /&gt;  printf( "%s\n", v2.p );&lt;BR /&gt;*/&lt;BR /&gt;} &lt;BR /&gt;&lt;BR /&gt;int main ()&lt;BR /&gt;{&lt;BR /&gt;  test_it0();&lt;BR /&gt;  test_it1();&lt;BR /&gt;  return 0;&lt;BR /&gt;}&lt;BR /&gt;----------/snip/--------------&lt;BR /&gt;&lt;BR /&gt;Unfortunately, removing the static char BLANK_VTRNR[2] = " "; instruction in the projekt does not have the same effect.&lt;BR /&gt;In the following you can see the part of the original code, which has the described error:&lt;BR /&gt;&lt;BR /&gt;int leseExterneHinweise_masch_storno( void ) {&lt;BR /&gt;   int  iRes = -1;    /* Fehler   */&lt;BR /&gt;   char cfDateiMitPfad[ 1024 ];&lt;BR /&gt;   int  iDateiId;&lt;BR /&gt;   BOOL bEofDatei = FALSE;&lt;BR /&gt;   int  iAnzSaetze = 0;&lt;BR /&gt;&lt;BR /&gt;   t_MaschStoExtern AktSatz;&lt;BR /&gt;   t_ptrMaschStoExtern pNeuerSatz = NULL;&lt;BR /&gt;   t_ptrMaschStoExtern pLetzterSatz = NULL;&lt;BR /&gt;&lt;BR /&gt;   t_AusdatFeldbeschreibung ExterneHinweise[ MASCHSTO_EXTERN_ANZ_FD ] =&lt;BR /&gt;   {  /* Typ,               Laenge               , Pointer zur&lt;BR /&gt;Variablen , Fehler */&lt;BR /&gt;      { AUSDAT_TYPE_STRING, MASCHSTO_ATTRNAME_LEN, AktSatz.cfAttributName, FALSE },&lt;BR /&gt;      { AUSDAT_TYPE_STRING, MASCHSTO_ATTRWERT_LEN, AktSatz.cfAttributWert, FALSE },&lt;BR /&gt;      { AUSDAT_TYPE_STRING, MASCHSTO_AUSGABE_LEN , AktSatz.cfAusgabe&lt;BR /&gt;  , FALSE }&lt;BR /&gt;   };&lt;BR /&gt;/* breakpoint here */&lt;BR /&gt;... &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;where&lt;BR /&gt;typedef struct s_AusdatFeldbeschreibung&lt;BR /&gt;         {&lt;BR /&gt;            short sTyp;&lt;BR /&gt;            int iLaenge;&lt;BR /&gt;            void *pWert;&lt;BR /&gt;            BOOL bFehlerhaft;&lt;BR /&gt;         } t_AusdatFeldbeschreibung;&lt;BR /&gt;&lt;BR /&gt;and&lt;BR /&gt;typedef struct sMaschStoExtern t_MaschStoExtern; typedef t_MaschStoExtern *t_ptrMaschStoExtern;&lt;BR /&gt;&lt;BR /&gt;struct sMaschStoExtern&lt;BR /&gt;{&lt;BR /&gt;   char cfAttributName[ MASCHSTO_ATTRNAME_LEN + 1 ];&lt;BR /&gt;   char cfAttributWert[ MASCHSTO_ATTRWERT_LEN + 1 ];&lt;BR /&gt;   char cfAusgabe[ MASCHSTO_AUSGABE_LEN + 1 ];&lt;BR /&gt;   t_ptrMaschStoExtern pNext;&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;When having a look at the structures on the breakpoint:&lt;BR /&gt;&amp;amp;AktSatz.cfAttributName = 0x800003ffff429cb0&lt;BR /&gt;&lt;BR /&gt;ExterneHinweise[0]:&lt;BR /&gt;sTyp = 6 ( according to definition of AUSDAT_TYPE_STRING ) iLaenge = 30 ( according to definition MASCHSTO_ATTRNAME_LEN ) pWert = 0xfffffffffffffea0 &lt;ERROR reading="" address="" bad="" address=""&gt; bFehlerhaft = 0 ( according to definition of FALSE )&lt;BR /&gt;&lt;BR /&gt;But:&lt;BR /&gt;&amp;amp;ExterneHinweise[0].pWert( signed char **) 0x800003ffff429d60&lt;BR /&gt;&lt;BR /&gt;Even the hint that the memset instruction before the declation of struct s2 v2 = { &amp;amp;v1.c }; in test_it0 is not c-compliant does not help very much as this "error" is not in the original code&lt;/ERROR&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Fri, 11 Feb 2005 05:01:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482953#M639972</guid>
      <dc:creator>FrankAtWork</dc:creator>
      <dc:date>2005-02-11T05:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: invalid pointer address</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482954#M639973</link>
      <description>Try :&lt;BR /&gt;&lt;BR /&gt;void test_it0( void )&lt;BR /&gt;{&lt;BR /&gt;    struct s1 v1;&lt;BR /&gt;    struct s2 v2;&lt;BR /&gt;&lt;BR /&gt;    v2.p = (void *) &amp;amp;v1.c;&lt;BR /&gt;&lt;BR /&gt;    printf( "1. %p\n", v2.p );&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;and similar for test_it1. This way you are not initialising v2.p in an automatic&lt;BR /&gt;aggregate way. Might be that your aCC compiler can't deal with it.&lt;BR /&gt;&lt;BR /&gt;Also,&lt;BR /&gt;&lt;BR /&gt;strcpy( (char *)v2.p, "Hallo ich schreibe mal was rein.." );&lt;BR /&gt;&lt;BR /&gt;I can't reproduce your problem, as I don't have an aCC compiler, only&lt;BR /&gt;gcc, which as you say works.&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Feb 2005 06:31:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482954#M639973</guid>
      <dc:creator>Stephen Keane</dc:creator>
      <dc:date>2005-02-11T06:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: invalid pointer address</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482955#M639974</link>
      <description>I just compiled and executed your snippet on using HP ANSI/C B.11.11.10 and all was well. The syntax was too bad to compile using aCC but this does suggest that if you upgrade to a later version of HP ANSI/C compiler than your 11.11.04 version then you will be fine.&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Feb 2005 11:06:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482955#M639974</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-02-11T11:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: invalid pointer address</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482956#M639975</link>
      <description>I would still upgrade to a later version of ANSI/C but there is a B.11.11.04 ANSI/C patch (PHSS_26792) which addresses a memset problem that looks exactly like yours.&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Feb 2005 11:13:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/3482956#M639975</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-02-11T11:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: invalid pointer address</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/5430953#M639976</link>
      <description>&lt;P&gt;&amp;gt;if this is C as opposed to C++. In C, variable declarations are only allowed at the top of a given block before any executable statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both C++ and C99 allow declarations after executable statements.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2011 14:10:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/invalid-pointer-address/m-p/5430953#M639976</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-12-28T14:10:32Z</dc:date>
    </item>
  </channel>
</rss>

