Commit 8f2d847f authored by Fabio D'Urso's avatar Fabio D'Urso Committed by Albert Astals Cid

Clang++ plugin that checks for usage errors in GooString::format-style calls

parent d7d61dcd
......@@ -18,7 +18,7 @@
// Copyright (C) 2006 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
// Copyright (C) 2008-2010, 2012 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2012, 2013 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright (C) 2012-2014 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright (C) 2013 Jason Crain <jason@aquaticape.us>
//
// To see a description of the changes please see the Changelog file that
......@@ -38,6 +38,12 @@
#include <stdlib.h> // for NULL
#include "gtypes.h"
#ifdef __clang__
# define GOOSTRING_FORMAT __attribute__((__annotate__("gooformat")))
#else
# define GOOSTRING_FORMAT
#endif
class GooString {
public:
......@@ -97,7 +103,7 @@ public:
// t -- GooString *
// w -- blank space; arg determines width
// To get literal curly braces, use {{ or }}.
static GooString *format(const char *fmt, ...);
static GooString *format(const char *fmt, ...) GOOSTRING_FORMAT;
static GooString *formatv(const char *fmt, va_list argList);
// Destructor.
......@@ -124,7 +130,7 @@ public:
GooString *append(const char *str, int lengthA=CALC_STRING_LEN);
// Append a formatted string.
GooString *appendf(const char *fmt, ...);
GooString *appendf(const char *fmt, ...) GOOSTRING_FORMAT;
GooString *appendfv(const char *fmt, va_list argList);
// Insert a character or string.
......
......@@ -17,6 +17,7 @@
// Copyright (C) 2005 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2014 Fabio D'Urso <fabiodurso@hotmail.it>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -33,6 +34,7 @@
#include <stdarg.h>
#include "poppler-config.h"
#include "goo/gtypes.h"
#include "goo/GooString.h"
enum ErrorCategory {
errSyntaxWarning, // PDF syntax error which can be worked around;
......@@ -53,6 +55,6 @@ extern void setErrorCallback(void (*cbk)(void *data, ErrorCategory category,
Goffset pos, char *msg),
void *data);
extern void CDECL error(ErrorCategory category, Goffset pos, const char *msg, ...);
extern void CDECL error(ErrorCategory category, Goffset pos, const char *msg, ...) GOOSTRING_FORMAT;
#endif
== Clang++ compiler plugin that checks usage of GooString::format-like functions ==
1) Compile the plugin with:
clang++ -shared -o goostring-format-checker.so goostring-format-checker.cc -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
2) Compile poppler and pass the following options to the clang++ compiler:
-Xclang -load -Xclang goostring-format-checker.so -Xclang -plugin -Xclang goostring-format-check
Example:
$ clang++ -shared -o goostring-format-checker.so goostring-format-checker.cc -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
$ export CXX=clang++
$ export CXXFLAGS="-Xclang -load -Xclang $PWD/goostring-format-checker.so -Xclang -add-plugin -Xclang goostring-format-checker"
$ mkdir build
$ cd build
$ cmake ../../..
$ make
This diff is collapsed.
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