Skip to content

sscanf() is broken (hangs / stores unexpected values) #16

@JayFoxRox

Description

@JayFoxRox

This code (taken from Neverball) leads to faulty behaviour:

#ifdef NXDK
#include <hal/video.h>
#include <hal/debug.h>
#else
#define debugPrint(...) printf(__VA_ARGS__)
#endif
#include <stdio.h>

int main() {

#ifdef NXDK
  XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);
#endif

  const char* line = "fullscreen                0";

  int ks, ke, vs;

  ks = -1;
  ke = -1;
  vs = -1;

  debugPrint("Starting scan\n");

  int ret = sscanf(line, " %n%*s%n %n", &ks, &ke, &vs);

  debugPrint("Result %d = %d %d %d\n", ret, ks, ke, vs);

#ifdef NXDK
  while(1);
#else
  return 0;
#endif
}

On my desktop with clang I get:

Starting scan
Result 0 = 0 10 26

On nxdk (in XQEMU) I only get:

Starting scan

(it seems to hang before the second debugPrint is reached)

On nxdk (in XQEMU) I got this with an older revision of the code which didn't retrieve / print int ret:

Starting scan
Result 1701995379 1819047270 10

Probably a bug in pdclib? CC @DevSolar

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions