Commit a8e93f46 authored by Albert Astals Cid's avatar Albert Astals Cid Committed by Albert Astals Cid

Make Object return const GooString pointer

This helps making sure noone is changing strings that belong to objects without us realizing.

In fact noone was doing except an ifdef for windows, fixed it to not modify the dict contents anymore
parent 07180b86
......@@ -456,7 +456,7 @@ find_annot_movie_for_action (PopplerDocument *document,
obj1 = annotObj.dictLookup ("T");
if (obj1.isString()) {
GooString *t = obj1.getString ();
const GooString *t = obj1.getString ();
if (title->cmp(t) == 0)
found = gTrue;
......
......@@ -114,7 +114,7 @@
// = (4 * (sqrt(2) - 1) / 3) * r
#define bezierCircle 0.55228475
static AnnotLineEndingStyle parseAnnotLineEndingStyle(GooString *string) {
static AnnotLineEndingStyle parseAnnotLineEndingStyle(const GooString *string) {
if (string != nullptr) {
if (!string->cmp("Square")) {
return annotLineEndingSquare;
......@@ -2097,11 +2097,11 @@ void AnnotText::initialize(PDFDoc *docA, Dict *dict) {
obj1 = dict->lookup("StateModel");
if (obj1.isString()) {
GooString *modelName = obj1.getString();
const GooString *modelName = obj1.getString();
Object obj2 = dict->lookup("State");
if (obj2.isString()) {
GooString *stateName = obj2.getString();
const GooString *stateName = obj2.getString();
if (!stateName->cmp("Marked")) {
state = stateMarked;
......
......@@ -9,6 +9,7 @@
// Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net>
// Copyright (C) 2012, 2017 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2012 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// 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
......@@ -234,7 +235,7 @@ Object getFileSpecNameForPlatform (Object *fileSpec)
// system-dependent path manipulation
#ifdef _WIN32
int i, j;
GooString *name = fileName.getString();
GooString *name = fileName.getString()->copy();
// "//...." --> "\...."
// "/x/...." --> "x:\...."
// "/server/share/...." --> "\\server\share\...."
......@@ -274,6 +275,7 @@ Object getFileSpecNameForPlatform (Object *fileSpec)
name->del(i);
}
}
fileName = Object(name);
#endif /* _WIN32 */
return fileName;
......
......@@ -854,7 +854,7 @@ FormWidget* FormField::findWidgetByRef (Ref aref)
GooString* FormField::getFullyQualifiedName() {
Object obj1;
Object parent;
GooString *parent_name;
const GooString *parent_name;
GooString *full_name;
GBool unicode_encoded = gFalse;
......@@ -1304,7 +1304,7 @@ int FormFieldText::parseDA(GooList* daToks)
if (obj.isDict()) {
Object objDA(obj.dictLookup("DA"));
if (objDA.isString()) {
GooString* da = objDA.getString();
const GooString* da = objDA.getString();
idx = tokenizeDA(da, daToks, "Tf") - 1;
}
}
......@@ -1647,7 +1647,7 @@ void FormFieldSignature::parseInfo()
// retrieve SigningTime
Object time_of_signing = sig_dict.dictLookup("M");
if (time_of_signing.isString()) {
GooString *time_str = time_of_signing.getString();
const GooString *time_str = time_of_signing.getString();
signature_info->setSigningTime(dateStringToTime(time_str)); // Put this information directly in SignatureInfo object
}
......
......@@ -2502,7 +2502,7 @@ public:
h *= 16777619;
}
void hash(char *p, int n) {
void hash(const char *p, int n) {
int i;
for (i = 0; i < n; ++i) {
hash(p[i]);
......@@ -2527,7 +2527,7 @@ int GfxFontDict::hashFontObject(Object *obj) {
void GfxFontDict::hashFontObject1(Object *obj, FNVHash *h) {
Object obj2;
GooString *s;
const GooString *s;
char *p;
double r;
int n, i;
......
......@@ -30,6 +30,7 @@
// Copyright (C) 2015 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2016 Marek Kasik <mkasik@redhat.com>
// Copyright (C) 2017 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// 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
......@@ -2481,7 +2482,7 @@ GfxColorSpace *GfxIndexedColorSpace::parse(GfxResources *res, Array *arr, Output
GfxColorSpace *baseA;
int indexHighA;
Object obj1;
char *s;
const char *s;
int i, j;
if (arr->getLength() != 4) {
......
......@@ -20,6 +20,7 @@
// Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net>
// Copyright (C) 2009 Ilya Gorenbein <igorenbein@finjan.com>
// Copyright (C) 2012 Tobias Koening <tobias.koenig@kdab.com>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// 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
......@@ -490,7 +491,7 @@ LinkLaunch::~LinkLaunch() {
//------------------------------------------------------------------------
LinkURI::LinkURI(Object *uriObj, GooString *baseURI) {
GooString *uri2;
const GooString *uri2;
int n;
char c;
......
......@@ -22,6 +22,7 @@
// Copyright (C) 2013, 2017, 2018 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2013 Adrian Perez de Castro <aperez@igalia.com>
// Copyright (C) 2016 Jakub Alba <jakubalba@gmail.com>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// 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
......@@ -236,7 +237,7 @@ public:
}
return type == objInt ? (double)intg : type == objInt64 ? (double)int64g : real;
}
GooString *getString() const { OBJECT_TYPE_CHECK(objString); return string; }
const GooString *getString() const { OBJECT_TYPE_CHECK(objString); return string; }
// After takeString() the only method that should be called for the object is free()
// because the object it's not expected to have a NULL string.
GooString *takeString() {
......
......@@ -18,6 +18,7 @@
// Copyright (C) 2009 Nick Jones <nick.jones@network-box.com>
// Copyright (C) 2016 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// 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
......@@ -71,7 +72,7 @@ OutlineItem::OutlineItem(Dict *dict, int refNumA, OutlineItem *parentA, XRef *xr
obj1 = dict->lookup("Title");
if (obj1.isString()) {
GooString *s = obj1.getString();
const GooString *s = obj1.getString();
titleLen = TextStringToUCS4(s, &title);
} else {
titleLen = 0;
......
......@@ -39,6 +39,7 @@
// Copyright (C) 2017 Fredrik Fornwall <fredrik@fornwall.net>
// Copyright (C) 2018 Ben Timby <btimby@gmail.com>
// Copyright (C) 2018 Evangelos Foutras <evangelos@foutrelis.com>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// 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
......@@ -683,7 +684,7 @@ GooString *PDFDoc::getDocInfoStringEntry(const char *key) {
}
static GBool
get_id (GooString *encodedidstring, GooString *id) {
get_id (const GooString *encodedidstring, GooString *id) {
const char *encodedid = encodedidstring->getCString();
char pdfid[pdfIdLength + 1];
int n;
......
......@@ -19,6 +19,7 @@
// Copyright (C) 2012 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// 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
......@@ -71,7 +72,8 @@ Object Parser::getObj(GBool simpleOnly,
Object obj;
Stream *str;
DecryptStream *decrypt;
GooString *s, *s2;
const GooString *s;
GooString *s2;
int c;
// refill buffer after inline image data
......
......@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Jeff Muizelaar <jeff@infidigm.net>
// Copyright (C) 2006-2010, 2012-2014, 2016, 2017 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2006-2010, 2012-2014, 2016, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
// Copyright (C) 2008 Julien Rebetez <julien@fhtagn.net>
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
......
......@@ -9,6 +9,7 @@
// Copyright 2014, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright 2015 Dmytro Morgun <lztoad@gmail.com>
// Copyright 2018 Adrian Johnson <ajohnson@redneon.com>
// Copyright 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
//========================================================================
......@@ -777,7 +778,7 @@ Attribute *Attribute::parseUserProperty(Dict *property)
obj = property->lookup("N");
if (obj.isString()) {
GooString *s = obj.getString();
const GooString *s = obj.getString();
name = s->getCString();
nameLen = s->getLength();
} else if (obj.isName())
......
......@@ -444,7 +444,7 @@ namespace Poppler {
QScopedPointer<GooString> goo(m_doc->doc->getDocInfoStringEntry(type.toLatin1().constData()));
QString str = UnicodeParsedString(goo.data());
return Poppler::convertDate(str.toLatin1().data());
return Poppler::convertDate(str.toLatin1().constData());
}
bool Document::setDate( const QString & key, const QDateTime & val )
......@@ -465,7 +465,7 @@ namespace Poppler {
QScopedPointer<GooString> goo(m_doc->doc->getDocInfoCreatDate());
QString str = UnicodeParsedString(goo.data());
return Poppler::convertDate(str.toLatin1().data());
return Poppler::convertDate(str.toLatin1().constData());
}
bool Document::setCreationDate( const QDateTime & val )
......@@ -486,7 +486,7 @@ namespace Poppler {
QScopedPointer<GooString> goo(m_doc->doc->getDocInfoModDate());
QString str = UnicodeParsedString(goo.data());
return Poppler::convertDate(str.toLatin1().data());
return Poppler::convertDate(str.toLatin1().constData());
}
bool Document::setModificationDate( const QDateTime & val )
......
......@@ -2,6 +2,7 @@
* Copyright (C) 2005, 2008, 2009, 2012, 2013, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2005, Brad Hards <bradh@frogmouth.net>
* Copyright (C) 2008, 2011, Pino Toscano <pino@kde.org>
* Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
*
* 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
......@@ -85,13 +86,13 @@ int EmbeddedFile::size() const
QDateTime EmbeddedFile::modDate() const
{
GooString *goo = m_embeddedFile->embFile() ? m_embeddedFile->embFile()->modDate() : nullptr;
const GooString *goo = m_embeddedFile->embFile() ? m_embeddedFile->embFile()->modDate() : nullptr;
return goo ? convertDate(goo->getCString()) : QDateTime();
}
QDateTime EmbeddedFile::createDate() const
{
GooString *goo = m_embeddedFile->embFile() ? m_embeddedFile->embFile()->createDate() : nullptr;
const GooString *goo = m_embeddedFile->embFile() ? m_embeddedFile->embFile()->createDate() : nullptr;
return goo ? convertDate(goo->getCString()) : QDateTime();
}
......
......@@ -5,6 +5,7 @@
* Copyright (C) 2008, Carlos Garcia Campos <carlosgc@gnome.org>
* Copyright (C) 2015-2017, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2017, Hubert Figuière <hub@figuiere.net>
* Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
*
* 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
......@@ -213,7 +214,7 @@ namespace Poppler
} else if ( (orderItem.isArray()) && (orderItem.arrayGetLength() > 0) ) {
parseOrderArray(lastItem, orderItem.getArray());
} else if ( orderItem.isString() ) {
GooString *label = orderItem.getString();
const GooString *label = orderItem.getString();
OptContentItem *header = new OptContentItem ( UnicodeParsedString ( label ) );
m_headerOptContentItems.append( header );
addChild( parentNode, header );
......
......@@ -1962,7 +1962,7 @@ height = dummy.height();
/**
Conversion from PDF date string format to QDateTime
*/
POPPLER_QT5_EXPORT QDateTime convertDate( char *dateString );
POPPLER_QT5_EXPORT Q_DECL_DEPRECATED QDateTime convertDate( char *dateString );
/**
Conversion from PDF date string format to QDateTime
......
......@@ -102,7 +102,7 @@ void TestDateConv::checkDates()
QFETCH(QDate, day);
QFETCH(QTime, time);
QCOMPARE( Poppler::convertDate(input.data()), QDateTime(day, time, Qt::UTC) );
QCOMPARE( Poppler::convertDate(input.constData()), QDateTime(day, time, Qt::UTC) );
}
void TestDateConv::checkInvalidDates_data()
......@@ -134,7 +134,7 @@ void TestDateConv::checkInvalidDates()
{
QFETCH(QByteArray, input);
QCOMPARE(Poppler::convertDate(input.data()), QDateTime());
QCOMPARE(Poppler::convertDate(input.constData()), QDateTime());
}
QTEST_GUILESS_MAIN(TestDateConv)
......
......@@ -162,8 +162,8 @@ static GBool compareObjects(Object *objA, Object *objB)
if (objB->getType() != objString) {
return gFalse;
} else {
GooString *strA = objA->getString();
GooString *strB = objB->getString();
const GooString *strA = objA->getString();
const GooString *strB = objB->getString();
return (strA->cmp(strB) == 0);
}
}
......
......@@ -22,6 +22,7 @@
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright (C) 2013 Adrian Perez de Castro <aperez@igalia.com>
// Copyright (C) 2013 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// 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
......@@ -125,7 +126,7 @@ static const ArgDesc argDesc[] = {
static void printInfoString(Dict *infoDict, const char *key, const char *text,
UnicodeMap *uMap) {
GooString *s1;
const GooString *s1;
Unicode *u;
char buf[8];
int i, n, len;
......@@ -145,7 +146,7 @@ static void printInfoString(Dict *infoDict, const char *key, const char *text,
}
static void printInfoDate(Dict *infoDict, const char *key, const char *text) {
char *s;
const char *s;
int year, mon, day, hour, min, sec, tz_hour, tz_minute;
char tz;
struct tm tmStruct;
......@@ -189,7 +190,7 @@ static void printInfoDate(Dict *infoDict, const char *key, const char *text) {
static void printISODate(Dict *infoDict, const char *key, const char *text)
{
char *s;
const char *s;
int year, mon, day, hour, min, sec, tz_hour, tz_minute;
char tz;
......
......@@ -25,6 +25,7 @@
// Copyright (C) 2014 Pino Toscano <pino@kde.org>
// Copyright (C) 2015 William Bader <williambader@hotmail.com>
// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// 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
......@@ -457,7 +458,7 @@ int main(int argc, char *argv[]) {
static GooString* getInfoString(Dict *infoDict, const char *key) {
Object obj;
// Raw value as read from PDF (may be in pdfDocEncoding or UCS2)
GooString *rawString;
const GooString *rawString;
// Value converted to unicode
Unicode *unicodeString;
int unicodeLength;
......@@ -499,7 +500,7 @@ static GooString* getInfoString(Dict *infoDict, const char *key) {
static GooString* getInfoDate(Dict *infoDict, const char *key) {
Object obj;
char *s;
const char *s;
int year, mon, day, hour, min, sec, tz_hour, tz_minute;
char tz;
struct tm tmStruct;
......
......@@ -26,6 +26,7 @@
// Copyright (C) 2013 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
// Copyright (C) 2015 Jeremy Echols <jechols@uoregon.edu>
// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// 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
......@@ -439,7 +440,7 @@ int main(int argc, char *argv[]) {
static void printInfoString(FILE *f, Dict *infoDict, const char *key,
const char *text1, const char *text2, UnicodeMap *uMap) {
GooString *s1;
const GooString *s1;
GBool isUnicode;
Unicode u;
char buf[9];
......@@ -478,7 +479,7 @@ static void printInfoString(FILE *f, Dict *infoDict, const char *key,
static void printInfoDate(FILE *f, Dict *infoDict, const char *key, const char *fmt) {
Object obj = infoDict->lookup(key);
if (obj.isString()) {
char *s = obj.getString()->getCString();
const char *s = obj.getString()->getCString();
if (s[0] == 'D' && s[1] == ':') {
s += 2;
}
......
......@@ -11,6 +11,7 @@
// Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2013 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2015 Arthur Stavisky <vovodroid@gmail.com>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
//========================================================================
......@@ -226,14 +227,14 @@ int main (int argc, char *argv[])
if (intent.isDict()) {
Object idf = intent.dictLookup("OutputConditionIdentifier");
if (idf.isString()) {
GooString *gidf = idf.getString();
const GooString *gidf = idf.getString();
GBool removeIntent = gTrue;
for (int k = 0; k < pageintents.arrayGetLength(); k++) {
Object pgintent = pageintents.arrayGet(k, 0);
if (pgintent.isDict()) {
Object pgidf = pgintent.dictLookup("OutputConditionIdentifier");
if (pgidf.isString()) {
GooString *gpgidf = pgidf.getString();
const GooString *gpgidf = pgidf.getString();
if (gpgidf->cmp(gidf) == 0) {
removeIntent = gFalse;
break;
......
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