title: getgrnam() causing error for no apparent reason?
body: <p>I am getting an error that makes no sense. I have the following code -</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;grp.h&gt;
  
  gid_t groupIdFromName(const char *name)
  {
      struct group *grp;
      gid_t g;
      char *endptr;
  
      if (name == NULL || *name == '\0')
          return -1;
  
      g = strtol(name, &amp;endptr, 10);
      if (*endptr == '\0')
          return g;
  
      grp = getgrnam(name);
      if (grp == NULL)
          return -1;
  
      return grp-&gt;gr_gid;
  }
  
  int main(int argc, char** argv) {
    return (EXIT_SUCCESS);
  }
  </code></pre>
  
  <p>I am using NetBeans in Linux Mint and when I try and while my program builds without problems, when I try and run it I get the following error -</p>
  
  <pre><code>Signal received: SIGSEGV (?) with sigcode ? (?)
  From process: ?
  </code></pre>
  
  <p>If I comment out the line <code>grp = getgrnam(name);</code> this error goes away. But I don't understand why this line should cause it to fail, particularly since my main method is blank.</p>