mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-11-25 18:33:51 +01:00
Fix format-string bugs by adding __attribute__((__format__)) in all applicable
places and fixing all warnings my gcc produced. Among other things, this should fix several segfaults (including one I just ran into).
This commit is contained in:
+1
-1
@@ -983,7 +983,7 @@ void PragmaDeclaration::semantic(Scope *sc)
|
||||
}
|
||||
else
|
||||
{
|
||||
error("command '%s' invalid");
|
||||
error("command '%s' invalid", expr->toChars());
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -122,8 +122,8 @@ struct Dsymbol : Object
|
||||
char *locToChars();
|
||||
int equals(Object *o);
|
||||
int isAnonymous();
|
||||
void error(Loc loc, const char *format, ...);
|
||||
void error(const char *format, ...);
|
||||
void error(Loc loc, const char *format, ...) IS_PRINTF(3);
|
||||
void error(const char *format, ...) IS_PRINTF(2);
|
||||
void checkDeprecated(Loc loc, Scope *sc);
|
||||
Module *getModule(); // module where declared
|
||||
Module *getCompilationModule(); // possibly different for templates
|
||||
|
||||
+4
-4
@@ -1466,7 +1466,7 @@ void IntegerExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
|
||||
case Tdchar: // BUG: need to cast(dchar)
|
||||
if ((uinteger_t)v > 0xFF)
|
||||
{
|
||||
buf->printf("'\\U%08x'", v);
|
||||
buf->printf("'\\U%08x'", (unsigned)v);
|
||||
break;
|
||||
}
|
||||
case Tchar:
|
||||
@@ -2934,7 +2934,7 @@ void ArrayLiteralExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
|
||||
void ArrayLiteralExp::toMangleBuffer(OutBuffer *buf)
|
||||
{
|
||||
size_t dim = elements ? elements->dim : 0;
|
||||
buf->printf("A%u", dim);
|
||||
buf->printf("A%zu", dim);
|
||||
for (size_t i = 0; i < dim; i++)
|
||||
{ Expression *e = (Expression *)elements->data[i];
|
||||
e->toMangleBuffer(buf);
|
||||
@@ -3068,7 +3068,7 @@ void AssocArrayLiteralExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
|
||||
void AssocArrayLiteralExp::toMangleBuffer(OutBuffer *buf)
|
||||
{
|
||||
size_t dim = keys->dim;
|
||||
buf->printf("A%u", dim);
|
||||
buf->printf("A%zu", dim);
|
||||
for (size_t i = 0; i < dim; i++)
|
||||
{ Expression *key = (Expression *)keys->data[i];
|
||||
Expression *value = (Expression *)values->data[i];
|
||||
@@ -3284,7 +3284,7 @@ void StructLiteralExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
|
||||
void StructLiteralExp::toMangleBuffer(OutBuffer *buf)
|
||||
{
|
||||
size_t dim = elements ? elements->dim : 0;
|
||||
buf->printf("S%u", dim);
|
||||
buf->printf("S%zu", dim);
|
||||
for (size_t i = 0; i < dim; i++)
|
||||
{ Expression *e = (Expression *)elements->data[i];
|
||||
if (e)
|
||||
|
||||
+2
-2
@@ -98,8 +98,8 @@ struct Expression : Object
|
||||
void print();
|
||||
char *toChars();
|
||||
virtual void dump(int indent);
|
||||
void error(const char *format, ...);
|
||||
void warning(const char *format, ...);
|
||||
void error(const char *format, ...) IS_PRINTF(2);
|
||||
void warning(const char *format, ...) IS_PRINTF(2);
|
||||
virtual void rvalue();
|
||||
|
||||
static Expression *combine(Expression *e1, Expression *e2);
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ struct Html
|
||||
|
||||
Html(const char *sourcename, unsigned char *base, unsigned length);
|
||||
|
||||
void error(const char *format, ...);
|
||||
void error(const char *format, ...) IS_PRINTF(2);
|
||||
void extractCode(OutBuffer *buf);
|
||||
void skipTag();
|
||||
void skipString();
|
||||
|
||||
+2
-2
@@ -292,8 +292,8 @@ struct Lexer
|
||||
unsigned wchar(unsigned u);
|
||||
TOK number(Token *t);
|
||||
TOK inreal(Token *t);
|
||||
void error(const char *format, ...);
|
||||
void error(Loc loc, const char *format, ...);
|
||||
void error(const char *format, ...) IS_PRINTF(2);
|
||||
void error(Loc loc, const char *format, ...) IS_PRINTF(3);
|
||||
void pragma();
|
||||
unsigned decodeUTF();
|
||||
void getDocComment(Token *t, unsigned lineComment);
|
||||
|
||||
+10
-2
@@ -76,6 +76,14 @@ the target object file format:
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef IS_PRINTF
|
||||
# ifdef __GNUC__
|
||||
# define IS_PRINTF(FMTARG) __attribute((__format__ (__printf__, (FMTARG), (FMTARG)+1) ))
|
||||
# else
|
||||
# define IS_PRINTF(FMTARG)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef IN_GCC
|
||||
/* Changes for the GDC compiler by David Friedman */
|
||||
#endif
|
||||
@@ -395,9 +403,9 @@ enum MATCH
|
||||
MATCHexact // exact match
|
||||
};
|
||||
|
||||
void warning(Loc loc, const char *format, ...);
|
||||
void warning(Loc loc, const char *format, ...) IS_PRINTF(2);
|
||||
void vwarning(Loc loc, const char *format, va_list);
|
||||
void error(Loc loc, const char *format, ...);
|
||||
void error(Loc loc, const char *format, ...) IS_PRINTF(2);
|
||||
void verror(Loc loc, const char *format, va_list);
|
||||
void fatal();
|
||||
void err_nomem();
|
||||
|
||||
+2
-2
@@ -267,8 +267,8 @@ struct Type : Object
|
||||
Type *next;
|
||||
Type *nextOf() { return next; }
|
||||
|
||||
static void error(Loc loc, const char *format, ...);
|
||||
static void warning(Loc loc, const char *format, ...);
|
||||
static void error(Loc loc, const char *format, ...) IS_PRINTF(2);
|
||||
static void warning(Loc loc, const char *format, ...) IS_PRINTF(2);
|
||||
|
||||
#if IN_DMD
|
||||
// For backend
|
||||
|
||||
+11
-3
@@ -18,6 +18,14 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifndef IS_PRINTF
|
||||
# ifdef __GNUC__
|
||||
# define IS_PRINTF(FMTARG) __attribute((__format__ (__printf__, (FMTARG), (FMTARG)+1) ))
|
||||
# else
|
||||
# define IS_PRINTF(FMTARG)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef size_t hash_t;
|
||||
|
||||
#include "dchar.h"
|
||||
@@ -29,9 +37,9 @@ int wcharIsAscii(wchar_t *, unsigned len);
|
||||
|
||||
int bstrcmp(unsigned char *s1, unsigned char *s2);
|
||||
char *bstr2str(unsigned char *b);
|
||||
void error(const char *format, ...);
|
||||
void error(const char *format, ...) IS_PRINTF(1);
|
||||
void error(const wchar_t *format, ...);
|
||||
void warning(const char *format, ...);
|
||||
void warning(const char *format, ...) IS_PRINTF(1);
|
||||
|
||||
#ifndef TYPEDEFS
|
||||
#define TYPEDEFS
|
||||
@@ -291,7 +299,7 @@ struct OutBuffer : Object
|
||||
void fill0(unsigned nbytes);
|
||||
void align(unsigned size);
|
||||
void vprintf(const char *format, va_list args);
|
||||
void printf(const char *format, ...);
|
||||
void printf(const char *format, ...) IS_PRINTF(2);
|
||||
#if M_UNICODE
|
||||
void vprintf(const unsigned short *format, va_list args);
|
||||
void printf(const unsigned short *format, ...);
|
||||
|
||||
+2
-2
@@ -104,8 +104,8 @@ struct Statement : Object
|
||||
void print();
|
||||
char *toChars();
|
||||
|
||||
void error(const char *format, ...);
|
||||
void warning(const char *format, ...);
|
||||
void error(const char *format, ...) IS_PRINTF(2);
|
||||
void warning(const char *format, ...) IS_PRINTF(2);
|
||||
virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
||||
virtual TryCatchStatement *isTryCatchStatement() { return NULL; }
|
||||
virtual GotoStatement *isGotoStatement() { return NULL; }
|
||||
|
||||
Reference in New Issue
Block a user