sprintf bad

This commit is contained in:
espie 2003-08-22 17:57:20 +00:00
parent 37ff30aa59
commit 542c9543c2
3 changed files with 87 additions and 3 deletions

View File

@ -0,0 +1,63 @@
$OpenBSD: patch-manage_C,v 1.1 2003/08/22 17:57:20 espie Exp $
--- manage.C.orig 2003-08-22 19:46:19.000000000 +0200
+++ manage.C 2003-08-22 19:47:34.000000000 +0200
@@ -127,18 +127,18 @@ void _manage::put_info()
int posx = MARGIN * 2 + (WSIZE << scale_log2) + 2;
wbase.string(posx, 25, "SCORE");
- sprintf(s, "%09d", score);
+ snprintf(s, sizeof s, "%09d", score);
wbase.string(posx, 40, s);
wbase.string(posx, 55, "STAGE");
- sprintf(s, "%09d", scene_num + 1);
+ snprintf(s, sizeof s, "%09d", scene_num + 1);
wbase.string(posx, 70, s);
wbase.string(posx, 85, "SHIPS");
if (!cheat_mode)
- sprintf(s, "%09d", ships);
+ snprintf(s, sizeof s, "%09d", ships);
else
- sprintf(s, "999999999");
+ snprintf(s, sizeof s, "999999999");
wbase.string(posx, 100, s);
}
@@ -147,7 +147,7 @@ void _manage::put_score()
static char s[1024];
int posx = MARGIN * 2 + (WSIZE << scale_log2) + 2;
- sprintf(s, "%09d", score);
+ snprintf(s, sizeof s, "%09d", score);
wbase.string(posx, 40, s);
score_changed = 0;
}
@@ -165,7 +165,7 @@ void _manage::flush_score()
}
else {
wbase.string(posx, 25, "SCORE");
- sprintf(s, "%09d", score);
+ snprintf(s, sizeof s, "%09d", score);
wbase.string(posx, 40, s);
}
if (flush_score_count == 0) flush_score_count = -1;
@@ -184,7 +184,7 @@ void _manage::flush_ships()
}
else {
wbase.string(posx, 85, "SHIPS");
- sprintf(s, "%09d", ships);
+ snprintf(s, sizeof s, "%09d", ships);
wbase.string(posx, 100, s);
}
}
@@ -343,7 +343,7 @@ void _manage::add_score(int sc)
score_changed = 1;
}
-void _manage::get_highscore(char *s)
+void _manage::get_highscore(char *s, size_t n)
{
- sprintf(s, "high score : %09d", highscore);
+ snprintf(s, n, "high score : %09d", highscore);
}

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-manage_h,v 1.1 2003/08/22 17:57:20 espie Exp $
--- manage.h.orig 2003-08-22 19:47:45.000000000 +0200
+++ manage.h 2003-08-22 19:47:50.000000000 +0200
@@ -62,7 +62,7 @@ class _manage {
static void plus_key();
static void minus_key();
static void add_score(int sc);
- static void get_highscore(char *s);
+ static void get_highscore(char *s, size_t);
static inline int state_playing(){return (state == playing);}
};

View File

@ -1,6 +1,15 @@
$OpenBSD: patch-screen_C,v 1.1 2002/10/06 00:49:03 naddy Exp $
--- screen.C.orig Wed Mar 13 17:34:38 1996
+++ screen.C Sun Oct 6 00:55:01 2002
$OpenBSD: patch-screen_C,v 1.2 2003/08/22 17:57:20 espie Exp $
--- screen.C.orig 1996-03-13 17:34:38.000000000 +0100
+++ screen.C 2003-08-22 19:48:09.000000000 +0200
@@ -83,7 +83,7 @@ void _screen::title()
{
char s[256];
int pos = (WSIZE/2)*((1<<scale_log2)-1);
- manage.get_highscore(s);
+ manage.get_highscore(s, sizeof s);
wchip.clear();
wchip.foreground(pixel_f0);
wchip.font("-adobe-new century "
@@ -103,7 +103,6 @@ void _screen::title()
wchip.string_back(85+pos, 205+pos, "'q' to quit");
wchip.set_position(0, 0);