Avoid a crash when there is no filename associated with a token

This commit is contained in:
Pierre Pronchery 2010-08-24 23:33:12 +00:00
parent f496161ae0
commit 944ae4ca93

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $Id$ */
/* Copyright (c) 2008 Pierre Pronchery <khorben@defora.org> */ /* Copyright (c) 2010 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */ /* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -41,8 +41,7 @@ struct _Token
/* protected */ /* protected */
/* functions */ /* functions */
/* token_new /* token_new */
* PRE filename must be non-NULL */
Token * token_new(String const * filename, unsigned int line, unsigned int col) Token * token_new(String const * filename, unsigned int line, unsigned int col)
{ {
Token * token; Token * token;
@ -54,11 +53,11 @@ Token * token_new(String const * filename, unsigned int line, unsigned int col)
return NULL; return NULL;
token->code = 0; token->code = 0;
token->string = NULL; token->string = NULL;
token->filename = string_new(filename); token->filename = (filename != NULL) ? string_new(filename) : NULL;
token->line = line; token->line = line;
token->col = col; token->col = col;
token->data = NULL; token->data = NULL;
if(token->filename == NULL) if(filename != NULL && token->filename == NULL)
{ {
error_set_code(1, "%s", strerror(errno)); error_set_code(1, "%s", strerror(errno));
object_delete(token); object_delete(token);