9front - general discussion about 9front
 help / color / mirror / Atom feed
From: qwx <qwx@sciops.net>
To: 9front@9front.org
Subject: Re: [9front] libstdio fscanf regression
Date: Fri, 15 May 2020 03:37:04 +0200	[thread overview]
Message-ID: <75EB9E866F3E63B257093D58220AE2F6@wopr.sciops.net> (raw)
In-Reply-To: <80954AE3C6C5B7FA9CEE3F96050E744A@eigenstate.org>

With this patch, fscanf returns the correct value, but the second string isn't
correctly nul terminated.
games/doom now crashes in crazy ways since it doesn't really do validation of
the config file's values.

I tweaked your test code:

#include <u.h>
#include <libc.h>
#include <stdio.h>

void
main(int, char **)
{
	char def[80], strparm[128];

	while(scanf("%79s %[^\n]\n", def, strparm) == 2)
		print("%s %s\n", def, strparm);
	exits(nil);
}


Test config file:

mouse_sensitivity		6
sfx_volume		2
music_volume		15
show_messages		1
key_right		174
key_left		172
key_up		119
key_down		115
key_strafeleft		97
key_straferight		100
key_fire		157
key_use		32
key_strafe		184
key_speed		182
autorun		1
use_mouse		1
mouseb_fire		0
mouseb_strafe		2
mouseb_forward		1
use_joystick		0
joyb_fire		0
joyb_strafe		1
joyb_use		3
joyb_speed		2
screenblocks		10
detaillevel		0
snd_channels		8
usegamma		1
chatmacro0		"No"
chatmacro1		"I'm ready to kick butt!"
chatmacro2		"I'm OK."
chatmacro3		"I'm not looking too good!"
chatmacro4		"Help!"
chatmacro5		"You suck!"
chatmacro6		"Next time, scumbag..."
chatmacro7		"Come here!"
chatmacro8		"I'll take care of it."
chatmacro9		"Yes"


Results:

mouse_sensitivity 6
sfx_volume 2
music_volume 15
show_messages 15
key_right 174
key_left 172
key_up 119
key_down 115
key_strafeleft 975
key_straferight 100
key_fire 157
key_use 327
key_strafe 184
key_speed 182
autorun 182
use_mouse 182
mouseb_fire 082
mouseb_strafe 282
mouseb_forward 182
use_joystick 082
joyb_fire 082
joyb_strafe 182
joyb_use 382
joyb_speed 282
screenblocks 102
detaillevel 002
snd_channels 802
usegamma 102
chatmacro0 "No"
chatmacro1 "I'm ready to kick butt!"
chatmacro2 "I'm OK."y to kick butt!"
chatmacro3 "I'm not looking too good!"
chatmacro4 "Help!"t looking too good!"
chatmacro5 "You suck!"oking too good!"
chatmacro6 "Next time, scumbag..."od!"
chatmacro7 "Come here!"scumbag..."od!"
chatmacro8 "I'll take care of it."od!"
chatmacro9 "Yes" take care of it."od!"

Oddly, the results are slightly different from within doom's code:

[...]
usegamma 102
chatmacro0 "No"�5@
chatmacro1 "I'm ready to kick butt!"
chatmacro2 "I'm OK."y to kick butt!
chatmacro3 "I'm not looking too good!"
chatmacro4 "Help!"t looking too good!
chatmacro5 "You suck!"oking too good
chatmacro6 "Next time, scumbag..."o
chatmacro7 "Come here!"scumbag..."
chatmacro8 "I'll take care of it."
chatmacro9 "Yes" take care of it.

Thanks,

qwx


  reply	other threads:[~2020-05-15  1:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15  0:20 qwx
2020-05-15  0:51 ` [9front] " ori
2020-05-15  1:37   ` qwx [this message]
2020-05-15  1:42     ` ori
2020-05-15  2:06       ` qwx

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=75EB9E866F3E63B257093D58220AE2F6@wopr.sciops.net \
    --to=qwx@sciops.net \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).