delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/01/22/10:24:50

Date: Mon, 22 Jan 1996 18:16:30 +0300 (MSK)
From: "Alexander V. Lukyanov" <lav AT video DOT yars DOT free DOT net>
To: djgpp AT delorie DOT com
Subject: a bug in sscanf?

Hello,

I've found some strangeness in sscanf which I suspect to be a bug.
I'm using v2beta4.

Here is a simple test program:
---8<---
#include <stdio.h>

int main()
{
   char name[256];
   int ch_read;

   printf("sscanf=%d\n",sscanf("abc123","%255[a-zA-Z0-9]%n",name,&ch_read));
   printf("ch_read=%d\n",ch_read);
   printf("name=%s\n",name);

   return 0;
}
---8<---

It outputs:
---8<---
sscanf=1
ch_read=-1058078715
name=abc123
---8<---

That is ch_read is uninitialized and sscanf succseeded! :-(

I think it is because a bug in doscan.c. It checks 'fileended' variable
and immediately exits. But in the format string next token is '%n' which does
not require more input.

This test works correctly on Solaris2.4.
---
Alexander Lukyanov
lav AT video DOT yars DOT free DOT net

- Raw text -


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