Commit 280e04bd authored by David Bruce's avatar David Bruce

- Bugfix to prevent BlackOutline() from segfault if passed empty string

        - incorporation of several small patches from OpenSuse (thanks Lars Vogdt)



git-svn-id: svn://svn.debian.org/svn/tux4kids/tuxtype/trunk@822 47d30e19-490b-0410-9d18-e851f4e465b3
parent b4a10239
06 Jan 2009 - svn revision 822
[ David Bruce <davidstuartbruce@gmail.com> ]
- Bugfix to prevent BlackOutline() from segfault if passed empty string
- incorporation of several small patches from OpenSuse (thanks Lars Vogdt)
05 Jan 2009 - svn revision 821 05 Jan 2009 - svn revision 821
[ David Bruce <davidstuartbruce@gmail.com> ] [ David Bruce <davidstuartbruce@gmail.com> ]
- Bugfix for path for bundled fonts - caused error when run on non-Debian - Bugfix for path for bundled fonts - caused error when run on non-Debian
......
06 Jan 2009 - svn revision 822
[ David Bruce <davidstuartbruce@gmail.com> ]
- Bugfix to prevent BlackOutline() from segfault if passed empty string
05 Jan 2009 - svn revision 821
[ David Bruce <davidstuartbruce@gmail.com> ]
- Bugfix for path for bundled fonts - caused error when run on non-Debian
systems.
2008-11-22 gettextize <bug-gnu-gettext@gnu.org> 2008-11-22 gettextize <bug-gnu-gettext@gnu.org>
* m4/gettext.m4: Upgrade to gettext-0.17. * m4/gettext.m4: Upgrade to gettext-0.17.
......
...@@ -381,11 +381,20 @@ SDL_Surface* BlackOutline(const char *t, TTF_Font *font, SDL_Color *c) ...@@ -381,11 +381,20 @@ SDL_Surface* BlackOutline(const char *t, TTF_Font *font, SDL_Color *c)
SDL_Rect dstrect; SDL_Rect dstrect;
Uint32 color_key; Uint32 color_key;
LOG("Entering BlackOutline()\n");
if (!t || !font || !c) if (!t || !font || !c)
{ {
fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning."); fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.");
return NULL; return NULL;
} }
if (t[0] == '\0')
{
fprintf(stderr, "BlackOutline(): empty string, returning");
return NULL;
}
#ifndef HAVE_LIBSDL_PANGO #ifndef HAVE_LIBSDL_PANGO
black_letters = TTF_RenderUTF8_Blended(font, t, black); black_letters = TTF_RenderUTF8_Blended(font, t, black);
...@@ -460,6 +469,8 @@ SDL_Surface* BlackOutline(const char *t, TTF_Font *font, SDL_Color *c) ...@@ -460,6 +469,8 @@ SDL_Surface* BlackOutline(const char *t, TTF_Font *font, SDL_Color *c)
out = SDL_DisplayFormatAlpha(bg); out = SDL_DisplayFormatAlpha(bg);
SDL_FreeSurface(bg); SDL_FreeSurface(bg);
LOG("Leaving BlackOutline()\n");
return out; return out;
} }
...@@ -529,14 +540,14 @@ SDL_Surface* BlackOutline_Unicode(const Uint16* t, const TTF_Font* font, const S ...@@ -529,14 +540,14 @@ SDL_Surface* BlackOutline_Unicode(const Uint16* t, const TTF_Font* font, const S
SDL_Surface* BlackOutline_w(wchar_t* t, const TTF_Font* font, const SDL_Color* c, int size) SDL_Surface* BlackOutline_w(wchar_t* t, const TTF_Font* font, const SDL_Color* c, int size)
{ {
wchar_t wchar_tmp[1024]; wchar_t wchar_tmp[1024];
char tmp[1024]; char tmp[1024];
int i; int i;
wcsncpy( wchar_tmp, t, size); wcsncpy( wchar_tmp, t, size);
wchar_tmp[size]=0; wchar_tmp[size] = 0;
i=ConvertToUTF8( wchar_tmp, tmp); i = ConvertToUTF8( wchar_tmp, tmp);
tmp[i]=0; tmp[i] = 0;
return BlackOutline(tmp, font, c); return BlackOutline(tmp, font, c);
} }
......
...@@ -26,6 +26,7 @@ Sreyas Kurumanghat <k.sreyas@gmail.com> ...@@ -26,6 +26,7 @@ Sreyas Kurumanghat <k.sreyas@gmail.com>
#include "globals.h" #include "globals.h"
#include "funcs.h" #include "funcs.h"
#include "SDL_extras.h"
...@@ -237,14 +238,14 @@ int GetFinger(int i) ...@@ -237,14 +238,14 @@ int GetFinger(int i)
{ {
if (i == -1) if (i == -1)
{ {
fprintf(stderr, "GetFinger() - Unicode char '%C' not found in list.\n"); fprintf(stderr, "GetFinger() - Unicode char '%C' not found in list.\n",i);
return -2; return -2;
} }
if ((keyboard_list[i].finger < 0) if ((keyboard_list[i].finger < 0)
|| (keyboard_list[i].finger > 9)) || (keyboard_list[i].finger > 9))
{ {
fprintf(stderr, "GetFinger() - Unicode char '%C' has no valid finger.\n"); fprintf(stderr, "GetFinger() - Unicode char '%C' has no valid finger.\n",i);
return -1; return -1;
} }
...@@ -1248,6 +1249,7 @@ int map_keys(wchar_t wide_char,kbd_char* keyboard_entry) ...@@ -1248,6 +1249,7 @@ int map_keys(wchar_t wide_char,kbd_char* keyboard_entry)
keyboard_entry->finger=-1; keyboard_entry->finger=-1;
break; break;
} }
return 0;
} }
void GenerateKeyboard(SDL_Surface* keyboard) void GenerateKeyboard(SDL_Surface* keyboard)
...@@ -1490,6 +1492,8 @@ static int add_char(wchar_t uc) ...@@ -1490,6 +1492,8 @@ static int add_char(wchar_t uc)
LOG ("Unable to add unicode - list at max capacity"); LOG ("Unable to add unicode - list at max capacity");
return -1; return -1;
} }
// We never want to get here...
return -1;
} }
......
...@@ -37,7 +37,7 @@ int CheckFile(const char* file) ...@@ -37,7 +37,7 @@ int CheckFile(const char* file)
if (!file) if (!file)
{ {
fprintf(stderr, "CheckFile(): invalid char* argument!"); fprintf(stderr, "CheckFile(): invalid char* argument!");
return; return -1;
} }
DEBUGCODE {fprintf(stderr, "CheckFile() - checking: %s\n", file);} DEBUGCODE {fprintf(stderr, "CheckFile() - checking: %s\n", file);}
...@@ -481,6 +481,8 @@ Mix_Chunk* LoadSound(const char* datafile ) ...@@ -481,6 +481,8 @@ Mix_Chunk* LoadSound(const char* datafile )
tempChunk = Mix_LoadWAV(fn); tempChunk = Mix_LoadWAV(fn);
return tempChunk; return tempChunk;
} }
// We never want to get here...
return tempChunk;
} }
...@@ -509,4 +511,6 @@ Mix_Music* LoadMusic(const char* datafile ) ...@@ -509,4 +511,6 @@ Mix_Music* LoadMusic(const char* datafile )
temp_music = Mix_LoadMUS(fn); temp_music = Mix_LoadMUS(fn);
return temp_music; return temp_music;
} }
// We never want to get here...
return temp_music;
} }
...@@ -24,6 +24,7 @@ Sreyas Kurumanghat <k.sreyas@gmail.com> ...@@ -24,6 +24,7 @@ Sreyas Kurumanghat <k.sreyas@gmail.com>
#include "globals.h" #include "globals.h"
#include "funcs.h" #include "funcs.h"
#include "SDL_extras.h" #include "SDL_extras.h"
#include "ConvertUTF.h"
#define MAX_PHRASES 256 #define MAX_PHRASES 256
#define MAX_PHRASE_LENGTH 256 #define MAX_PHRASE_LENGTH 256
...@@ -98,7 +99,6 @@ static SDL_Rect keyboard_loc; ...@@ -98,7 +99,6 @@ static SDL_Rect keyboard_loc;
/*local function prototypes: */ /*local function prototypes: */
static int load_phrases(const char* phrase_file); static int load_phrases(const char* phrase_file);
static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width); static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width);
static int get_phrase(const wchar_t* phr);
static void recalc_positions(void); static void recalc_positions(void);
static void calc_font_sizes(void); static void calc_font_sizes(void);
static int practice_load_media(void); static int practice_load_media(void);
...@@ -229,16 +229,19 @@ int Phrases(wchar_t* pphrase ) ...@@ -229,16 +229,19 @@ int Phrases(wchar_t* pphrase )
smallfont, phrase_draw_width); smallfont, phrase_draw_width);
tmpsurf = BlackOutline_w(&phrases[cur_phrase][prev_wrap], tmpsurf = BlackOutline_w(&phrases[cur_phrase][prev_wrap],
smallfont, &white, wrap_pt + 1); smallfont, &white, wrap_pt + 1);
if (tmpsurf) if (tmpsurf)
{ {
SDL_BlitSurface(tmpsurf, NULL, screen, &phr_text_rect); SDL_BlitSurface(tmpsurf, NULL, screen, &phr_text_rect);
SDL_FreeSurface(tmpsurf); SDL_FreeSurface(tmpsurf);
tmpsurf = NULL; tmpsurf = NULL;
} }
/* Draw the text the player has typed so far: */ /* Draw the text the player has typed so far: */
tmpsurf = BlackOutline_w(&phrases[cur_phrase][prev_wrap], tmpsurf = BlackOutline_w(&phrases[cur_phrase][prev_wrap],
smallfont, &white, smallfont, &white,
cursor - prev_wrap); cursor - prev_wrap);
if (tmpsurf) if (tmpsurf)
{ {
SDL_BlitSurface(tmpsurf, NULL, screen, &user_text_rect); SDL_BlitSurface(tmpsurf, NULL, screen, &user_text_rect);
...@@ -575,6 +578,8 @@ int Phrases(wchar_t* pphrase ) ...@@ -575,6 +578,8 @@ int Phrases(wchar_t* pphrase )
case SDLK_x: tmp='x'; break; case SDLK_x: tmp='x'; break;
case SDLK_y: tmp='y'; break; case SDLK_y: tmp='y'; break;
case SDLK_z: tmp='z'; break; case SDLK_z: tmp='z'; break;
/* ignore other keys: */
default: break;
} }
/* If state has changed as direct result of keypress (e.g. F10), leave */ /* If state has changed as direct result of keypress (e.g. F10), leave */
...@@ -1244,7 +1249,6 @@ static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width) ...@@ -1244,7 +1249,6 @@ static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width)
int phr_length = 0; int phr_length = 0;
int test_w = 0; /* The width in pixels of the SDL-rendered string */ int test_w = 0; /* The width in pixels of the SDL-rendered string */
settings.debug_on = 1;
LOG("Entering find__next_wrap\n"); LOG("Entering find__next_wrap\n");
/* Make sure args OK: */ /* Make sure args OK: */
...@@ -1316,8 +1320,8 @@ static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width) ...@@ -1316,8 +1320,8 @@ static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width)
{ {
fprintf(stderr, "width exceeded, returning end of previous word as wrap point\n"); fprintf(stderr, "width exceeded, returning end of previous word as wrap point\n");
fprintf(stderr, "prev_word_end is %d\n", prev_word_end); fprintf(stderr, "prev_word_end is %d\n", prev_word_end);
fprintf(stderr, "leaving find_next_wrap()\n");
} }
settings.debug_on = 0;
return prev_word_end; return prev_word_end;
} }
else else
...@@ -1331,7 +1335,6 @@ static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width) ...@@ -1331,7 +1335,6 @@ static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width)
} }
/* We reached the end of the phrase without exceeding the width, */ /* We reached the end of the phrase without exceeding the width, */
/* so just return our current position: */ /* so just return our current position: */
settings.debug_on = 0;
return word_end; return word_end;
} }
else else
...@@ -1344,107 +1347,6 @@ static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width) ...@@ -1344,107 +1347,6 @@ static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width)
} }
static int get_phrase(const wchar_t* phr)
{
int pc = 0; // 'phrase count' (?)
int phr_widths[MAX_PHRASES] = { 0 };
int wrap_pt = 0, i = 0, c = 0, z = 0;
char fn[FNLEN];
int old_debug_on = settings.debug_on;
settings.debug_on = 1;
LOG("Entering get_phrase()\n");
/* If we didn't receive a phrase get the first one from the file...*/
if (wcsncmp((wchar_t*)"", phr, 40) == 0)
{
FILE* phrase_file;
/* set the phrases directory/file */
/* FIXME I think the phrases should be under data or the theme */
#ifdef WIN32
snprintf(fn, FNLEN - 1, "userdata/phrases.txt");
#else
snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/phrases.txt", getenv("HOME"));
#endif
DEBUGCODE { printf("get_phrases(): phrases file is '%s'\n", fn ); }
LOG("get_phrases(): trying to open phrases file\n");
phrase_file = fopen( fn, "r" );
if (phrase_file == NULL)
return(wrap_pt); /* why not just 'return 0;' ??? */
/* So now copy each line into phrases array: */
while (!feof(phrase_file) && pc < 256)
{
fscanf( phrase_file, "%[^\n]\n", phrases[pc] );
pc++;
DEBUGCODE {printf("%s", phrases[pc]);}
}
if (pc == MAX_PHRASES)
LOG("File contains more than MAX_PHRASES - stopping\n");
fclose(phrase_file);
pc--;
}
else
{
LOG("get_phrase() in else clause\n");
pc = 1;
wcsncpy(phrases[0], phr, MAX_PHRASE_LENGTH);
}
/* FIXME this seems to be broken - phr_widths[] has not yet been calculated! */
//Find wrapping point
for (c = 0; c <= pc; c++)
{
if (phr_widths[c] < 50) // If the phrase is less than 598 pixels wide
{
if (c == 0)
{
wrap_pt = wcslen(phrases[c]);
print_at(phrases[0], wrap_pt, 40, 10);
}
}
else
{
z = 0;
wrap_pt = 0;
for (i = 0; i < wcslen(phrases[c]); i++)
{
/* Should be safe (if no glyph, will have returned above) */
z ++;
if (wrap_pt == 0 && z > 50)
{
wrap_pt = i - 1;
break;
}
}
for (i = wrap_pt; i >= 0; i--)
{
if (wcsncmp((wchar_t*)" ", &phrases[c][i], 1) == 0)
{
wrap_pt = i-1;
break;
}
}
if (c == 0)
{
LOG("about to call print_at() near bottom\n");
print_at(phrases[0], wrap_pt, 40, 10);
}
}
}
LOG("Leaving get_phrase()\n");
settings.debug_on = old_debug_on;
return(wrap_pt);
}
static void print_at(const wchar_t *pphrase, int wrap, int x, int y) static void print_at(const wchar_t *pphrase, int wrap, int x, int y)
{ {
int z = 0; int z = 0;
...@@ -1497,6 +1399,7 @@ static void print_at(const wchar_t *pphrase, int wrap, int x, int y) ...@@ -1497,6 +1399,7 @@ static void print_at(const wchar_t *pphrase, int wrap, int x, int y)
DEBUGCODE { printf("Leaving print_at \n\n\n"); } DEBUGCODE { printf("Leaving print_at \n\n\n"); }
} }
static void next_letter(wchar_t *t, int c) static void next_letter(wchar_t *t, int c)
{ {
int i; int i;
......
...@@ -380,7 +380,7 @@ int TestLesson(void) ...@@ -380,7 +380,7 @@ int TestLesson(void)
/* Getting to here means "stop == 1", try to run chosen script: */ /* Getting to here means "stop == 1", try to run chosen script: */
if (load_script(fn) != 0) if (load_script(fn) != 0)
{ {
fprintf(stderr, "load_script() failed to load '%s'\n"); fprintf(stderr, "load_script() failed to load '%s'\n",fn);
return 0; // bail if any errors occur return 0; // bail if any errors occur
} }
......
...@@ -230,7 +230,7 @@ static int load_settings_filename(const char* fn) ...@@ -230,7 +230,7 @@ static int load_settings_filename(const char* fn)
if (!fp) if (!fp)
{ {
fprintf(stderr, "load_settings_filename(): no theme-specific settings found%s\n",fn); fprintf(stderr, "load_settings_filename(): no theme-specific settings found%s\n",fn);
return; return -1;
} }
if (!load_settings_fp(fp)) if (!load_settings_fp(fp))
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "globals.h" #include "globals.h"
#include "funcs.h" #include "funcs.h"
#include "SDL_extras.h"
SDL_Surface* letters[255] = {NULL}; //get rid of this SDL_Surface* letters[255] = {NULL}; //get rid of this
......
...@@ -1811,7 +1811,7 @@ static void ChooseWord(char *words_file) ...@@ -1811,7 +1811,7 @@ static void ChooseWord(char *words_file)
FILE *fp; FILE *fp;
int start,themes = 0; int start,themes,themest = 0;
int i,len; int i,len;
unsigned char fn[FNLEN]; unsigned char fn[FNLEN];
unsigned char str[FNLEN]; unsigned char str[FNLEN];
...@@ -1843,7 +1843,8 @@ static void ChooseWord(char *words_file) ...@@ -1843,7 +1843,8 @@ static void ChooseWord(char *words_file)
{ {
/* HACK: we should get the strings from file :) */ /* HACK: we should get the strings from file :) */
fscanf(fp, "%[^\n]\n", editWordW[themes]); fscanf(fp, "%[^\n]\n", editWordW[themes]);
strcpy(editWordY[themes++],editWordW[themes]); themest=themes;
strcpy(editWordY[themes++],editWordW[themest]);
} }
fclose(fp); fclose(fp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment