Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • pike pike
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 104
    • Issues 104
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • pikelang
  • pikepike
  • Issues
  • #5
Closed
Open
Issue created Aug 14, 2000 by Peter Bortas@zinoOwner

Bad handling of EOF in Stdio.FILE.gets()

Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=5

Reported by @grubba

From: Aleph One <aleph1@underground.org>
To: pike@idonex.se
Date: Tue, 11 Jul 2000 12:28:15 -0700
Subject: Stdio.FILE.gets()

There is a bug in the Stdio.FILE.gets() functions. The standard C library gets() function will read bytes until a terminating newline or an EOF. If it reaches the EOF it will replace the EOF by a null char and return the last "unterminated" last line. If you read again it returns NULL.

Pike's Stdio.FILE.gets() fails to return the last line of a file unless its terminated by a newline character.

    string gets()
    {
      int p,tmp=0;
      while((p=search(b, "\n", bpos+tmp)) == -1)
      {
        tmp=strlen(b)-bpos;
        if(!get_data()) return 0;
      }
      return extract(p-bpos, 1);
    }

should be something like:

    string gets()
    {
      int p,tmp=0;
      while((p=search(b, "\n", bpos+tmp)) == -1)
      {
        tmp=strlen(b)-bpos;
        if(!get_data())
        {
          if (bpos == sizeof(b))
            return 0;
          else
            return extract(sizeof(b)-bpos, 0);
        }
      }
      return extract(p-bpos, 1);
    }

Comments?

-- Aleph One / aleph1@underground.org http://underground.org/ KeyID 1024/948FD6B5 Fingerprint EE C9 E8 AA CB AF 09 61 8C 39 EA 47 A8 6A B8 01

Assignee
Assign to
Time tracking