Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
pike
pike
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 105
    • Issues 105
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • pikelang
  • pikepike
  • Issues
  • #5

Closed
Open
Opened 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
Pike 7.0
Milestone
Pike 7.0
Assign milestone
Time tracking
None
Due date
None
Reference: pikelang/pike#5