www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/11/18:31:36

Xref: news2.mv.net comp.os.msdos.djgpp:7080
From: rhawes AT dma DOT org (Richard L. Hawes)
Newsgroups: comp.os.msdos.djgpp
Subject: bug fix for libc in version 2.00 of djgpp
Date: 11 Aug 1996 03:35:21 GMT
Organization: Dayton Microcomputer Association; Dayton OH
Lines: 76
Message-ID: <4ujkdp$15d@sally.dma.org>
NNTP-Posting-Host: dmapub.dma.org
Summary: sscanf sometimes returns incorrect values, patch fix included.
Keywords: sscanf bugs patch libc
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

        Sometime sscanf will return the incorrect value.  For example,
run the following program with the first argument as "5" and it will 
return -1 (EOF) when it should  return 1:

        -       -       -       -       -       -       -       -
#include<stdio.h>

int main(int argc, char *argv[])
{
int i,j;

i=j=0;
printf(" %d \n", sscanf(argv[1], "%d-%d", &i, &j));
printf(" %d-%d\n", i, j);
}
        -       -       -       -       -       -       -       -

        At the end of this file is a patch for it.  Place this file in
your djgpp directory (after you unzip the library source code first of
coarse). Then type in the following lines at the dos prompt to fix it:

>patch <thisfile
>gcc -c src\libc\ansi\stdio\doscan.c
>ar r lib\liba  src\libc\ansi\stdio\docan.o

Patch will ignore this note.

*** src\libc\ansi\stdio/doscan.c        Wed Jan 24 04:31:46 1996
--- doscan.c    Sun Aug 11 01:22:08 1996
***************
*** 57,61 ****
    for (;;) switch (ch = *fmt++) {
    case '\0':
!     return (nmatch);
    case '%':
      if ((ch = *fmt++) == '%')
--- 57,61 ----
    for (;;) switch (ch = *fmt++) {
    case '\0':
!     return (nmatch? nmatch: -1);
    case '%':
      if ((ch = *fmt++) == '%')
***************
*** 100,104 ****
      }
      if (ch == '\0')
!       return(-1);
      if (_innum(ptr, ch, len, size, iop, scan_getc, scan_ungetc,
               &fileended) && ptr)
--- 100,104 ----
      }
      if (ch == '\0')
!       return(nmatch? nmatch: -1);
      if (_innum(ptr, ch, len, size, iop, scan_getc, scan_ungetc,
               &fileended) && ptr)
***************
*** 130,137 ****
      if (ch1 != ch) {
        if (ch1==EOF)
!       return(-1);
        scan_ungetc(ch1, iop);
        nchars--;
!       return(nmatch);
      }
    }
--- 130,137 ----
      if (ch1 != ch) {
        if (ch1==EOF)
!       return(nmatch? nmatch: -1);
        scan_ungetc(ch1, iop);
        nchars--;
!       return(nmatch? nmatch: -1);
      }
    }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019