summaryrefslogtreecommitdiff
path: root/sal/rtl/strtmpl.cxx
AgeCommit message (Collapse)Author
2017-07-05new loplugin unnecessaryparenNoel Grandin
Change-Id: Ic883a07b30069ca6342d7521c8ad890f4326f0ec Reviewed-on: https://gerrit.libreoffice.org/39549 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-06-08Avoid -fsanitize=signed-integer-overflowStephan Bergmann
...in recently introduced basic/qa/basic_coverage/test_string_overflow_safe.vb in CppunitTest_basic_macros Change-Id: Ib33272afa26e90729617cb86ae979c0b35b45f62
2017-06-07tdf#108039: check for nullptr in rtl_uString and OUStringMike Kaganski
rtl_[u]String_newConcat now checks allocation result to return early and avoid SIGSEGV. Other functions are not modified, to keep old behavior relying on allocation success and crashing early on OOM to avoid added overhead in performance-critical places. OUString operator+= now checks rtl_uString_newConcat result and throws std::bad_alloc on failure, to specifically address BASIC problem. It keeps strong exception guarantee of leaving this' state unaltered. Concatenation in BASIC now checks for bad string allocation (previously SIGSEGV was generated). Unit test included. Change-Id: I1513311d3d58eac43b2d2ec9a230e22dff0b4245 Reviewed-on: https://gerrit.libreoffice.org/37965 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Jenkins <ci@libreoffice.org>
2016-09-29tdf#83306: sal: fix compare of rtl::OUString/OString containing '\0'Michael Stahl
For whatever reason oox shape import code uses OUStrings that contain '\0' characters. The rtl_uString / rtl_String are allowed to contain '\0' but the strncmp/wcsncmp functions stop comparing on the first '\0', so use memcmp/wmemcmp instead. (regression from 281989007fd7dea997ed9a65f513f80b1aff67dd) Change-Id: If148927f19d065a21f32f3c14433b0bda7ae9301 Reviewed-on: https://gerrit.libreoffice.org/29384 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
2016-04-20loplugin:salbool: Automatic rewrite of sal_False/TrueStephan Bergmann
Change-Id: I6c656f991999791469015500aff1905fdb16ba65
2016-04-01tdf#97966 Drop 'static' keywordsWastack
Including no keywords from extern "C" blocks Change-Id: I87f2ed75888b51ec9e0cb75566bf7c2351b479b4 Reviewed-on: https://gerrit.libreoffice.org/23675 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2016-01-06tdf#39631 - branch hints: comment, and tweak variously, also use.Michael Meeks
Find a few million mis-predicted branches (according to callgrind) and annotate them. Mark string acquire/release as hot, and a number of deprecated methods as cold. Change-Id: I678b3981794221c97f9ebb70fd0161c0fda5dceb
2015-11-10loplugin:nullptr (automatic rewrite)Stephan Bergmann
Change-Id: I1bc6c87fcd6e5e96362623be94c59be216a3b2b8
2015-05-29loplugin:redundantcast: Work around OS X memchr bugStephan Bergmann
...where in C++ memchr does not have exactly the two overloads void const * memchr(void const *, int, size_t) void * memchr(void *, int, size_t) but rather the C void * memchr(void const *, int, size_t) shining through (see bugreport.apple.com issue 21128245 "non-conforming memchr in C++"), which gets in the way of the upcoming improved redundant const_cast check in loplugin:redundantcast. Change-Id: I7001e74e03429ef23682d52da28fca435130d775
2015-03-28Clean up C-style casts from pointers to voidStephan Bergmann
Change-Id: I5e370445affbcd32b05588111f74590bf24f39d6
2015-03-26const_cast: convert some C-style casts and remove some redundant onesStephan Bergmann
Change-Id: I03e43d219a65aa270f73a91896e0e7a567d424bc
2015-03-02Turn function-like macro into true functionStephan Bergmann
Change-Id: I70330b1f4844f33779f814377afaf90e0a219b1d
2015-03-02typoStephan Bergmann
Change-Id: Ifc03631b126ec19cb98cb42a258ca4880e868385
2015-02-05sal: add some argument checking assertions for strings and buffersMichael Stahl
Also remove some now redundant asserts from headers. Some of these actually trigger on unit tests so are commented out. Change-Id: I07c6b2b2bd175361691a141f22eec584e3ab8f0b
2015-02-05convert all remaining BOOST_STATIC_ASSERT to static_assertCaolán McNamara
and we can include a few less headers Change-Id: Id742849ff4c1c37a2b861aa3d6ab823f00ea87f8
2015-01-20Missing constStephan Bergmann
Change-Id: I13058a46526a1186deaa8fffde303c272c0cc8aa
2015-01-20Some more loplugin:cstylecast: salStephan Bergmann
Change-Id: Ie54d340478412e62b87d66e287fd8a3963e97898
2014-12-19Assert ASCII precond of rtl_uString_newFromAscii/LiteralStephan Bergmann
...and there is no reason for such a precond for rtl_string_newFromLiteral Change-Id: I27f7217c8db17cef860c37886d0f7e561dc852f8
2014-12-19IMPL_RTL_INTERN -> IMPL_RTL_IS_USTRINGStephan Bergmann
Change-Id: I9793f697f14118340bc6db89540fe50ad0b8ccbd
2014-10-03coverity#1241327 Dereference after null checkCaolán McNamara
Change-Id: I214884e9ee1d49dcc4db71f8744513468b912691
2014-10-03coverity#1241080 Dereference after null checkCaolán McNamara
Change-Id: I82113fcd4182f9557ba0e7258498b5d4e798bf03
2014-07-28Include <algorithm> for std::minTor Lillqvist
Change-Id: I012027c38a6d2b06a4bb0cb53743d350b124ccf4
2014-07-04Use standard library optimised routines for OUString/OStringNoel Grandin
..handling where possible. Change-Id: I0b071988ed266cc2745a8ca9705c106a05edc557 Reviewed-on: https://gerrit.libreoffice.org/10020 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
2014-03-31coverity#983373 Dereference before null checkCaolán McNamara
Change-Id: Ie2a6b5e71f76ff2900ff078fcc098e66927458ef
2014-02-18Stick to a single O[U]String hash functionStephan Bergmann
8f8bc0dcf3bc253ae49159d52db049767f476ced "Move string hash function into String class" had introduced a new getHash64 that, besides returning sal_uInt64 instead of just sal_Int32, didn't do sampling of only a handful of characters, but always computed the hash over all characters (as the usage in SfxItemSet and SdPage appears to require for either performance or approximated correctness). However, it would be advantageous to keep the stable URE interface as small as possible. Now, O(1) sampling was apparently considered state of the art when the rtl string classes were first created, closely copying java.lang.String, which at that time demanded sampling for hashCode(), too---but never sampling more than 15 characters, with the obvious (in hindsight, at least) performance catastrophes, so they changed it to O(n) somewhere along the way. Based on that, this commit changes the existing hash functions to not do sampling any more, and removes the newly introduced -64 variants again. (Where the extended value range of sal_uInt64 compared to sal_Int32 was hopefully not vital to the existing uses.) The old implementation used sampling only for strings of length >= 256, so I did a "make check" build with an instrumented hash function that flagged all uses with inputs of length >= 256, and grepped workdir/{Cppunit,Junit,Python}Test for hits. Of the 2849 hits encountered, 2845 where in the range from 256 to 295 characters, and only the remaining four where of 2472 characters. Those four were from CppunitTest_sc_subsequent_filters_test, importing long text into a cell, causing ScDocumentImport::setStringCell to call svl::SharedStringPool::intern, which internally uses an unordered_set. These results appear to justify the change. Change-Id: I78fcc3b0f07389bdf36a21701b95a1ff0a0d970f
2014-02-17sal: sal_Bool -> boolStephan Bergmann
Change-Id: I071a931660dafc1ee5950da527b042fb175255b8
2014-02-13Move string hash function into String class.Muthu Subramanian
hashCode() seems to do sampling while creating the hash. hashCode64() will not. Change-Id: Id30f5a2a774cf5244dbc00da9649e95a532484be
2013-10-09Fail fast at least in debug buildsStephan Bergmann
Change-Id: I266d5cf5b98827617f7ed65c94a772e28808f386
2013-09-30Clean up rtl/character.hxxStephan Bergmann
It is probably best to base the functions on Unicode code points instead of scalar values, now that they are also used from sal/rtl/strtmpl.cxx with UTF-16 code units and with arbitrary bytes (with values assumed to be a superset of ASCII, though). Rename compareAsciiIgnoreCase to compareIgnoreAsciiCase. Also, the corresponding tools::INetMIME functions can be removed completely; no need to keep them around as deprecated. Change-Id: I8d322177f4909e70a946e8186e3e0f7fa6d9a43e
2013-09-30Introduce ASCII case conversion and use more/rtl/character.hxx.Arnaud Versini
Also remove all others implementations. Change-Id: I1dc108a9103f087bd8ce591dff2ac5dd254746f8 Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
2013-08-22Various undefined behavior involving signed integersStephan Bergmann
as flagged by Clang -fsanitize=undefined Change-Id: Iff1aa4473d960009890b923fba734257ecd8b3ef
2013-08-20rtl::compareAsciiIgnoreCase cannot be used hereStephan Bergmann
...as its assert requires that both input characters are ASCII, which need not be the case in these compareIgnoreAsciiCase functions. (Even if they take one literal argument that must be strictly ASCII, the other argument can be an arbitrary Unicode string in the case of OUString or an arbitrary 8-bit string in the case of OString). The logically correct version of rtl::compareAsciiIgnoreCase would arguably be one that requires its two arguments to be valid UTF-32 code units, but that could not be used in these places either, as for OUString they operate on individual UTF-16 code units. rtl::compareAsciiIgnoreCase likely makes less sense after all than assumed in c8e39e66528affb66f1ae121fa36dd4ab31a9b0b "Introduce rtl::compareIgnoreCase and deprecate rtl/character.hxx equivalents," which this commit partly reverts. Change-Id: Ib2eed3a1896e83d9c66b0479a03f9ec51e1c4dc0
2013-08-19Introduce rtl::compareIgnoreCase and deprecate rtl/character.hxx equivalents.Arnaud Versini
Change-Id: Id90935fd2b0f904f89477792edc8140cfc31e91f Reviewed-on: https://gerrit.libreoffice.org/5412 Reviewed-by: Petr Mladek <pmladek@suse.cz> Tested-by: Petr Mladek <pmladek@suse.cz>
2013-06-13Introduce O[U]String::toUInt32Stephan Bergmann
...which has become necessary since bd60d41176da540b01d7583cfe00637431967f39 "Handle oveflow in O(U)String::toInt() functions" reduces values in the range (SAL_MAX_INT32 .. SAL_MAX_UINT32] to zero, but some calls of toInt32(16) relied on getting a correct (unsigned) value for the whole input range ["0" .. "FFFFFFFF"] (see libreoffice-4-1 commit 9bf6c83367cedb7be81bf67f30d2147d26c7a8c3 "Revert overflow checks in O[U]String::toInt{32,64} again"). Audited all uses of toInt32/64 with non-decimal radix. (There is still a TODO comment in oox/source/helper/attributelist.cxx, and stoc/source/typeconv/convert.cxx will still need some love and test code.) Change-Id: Iadaca1c0e41dab553687d0ce41c20c10cd657a95
2013-03-26No need for a template hereStephan Bergmann
Change-Id: I43262c984c311fcb1e1a9eca9b4dec4092351dea
2013-03-26Could the failing MSVC tinderbox be due to implementation-defined /Stephan Bergmann
...for negative integers in < C++11? Rather unlikely, but lets see... Change-Id: I9abfcbf2c0e409fab4c77b62e5f734d3c2cc2719
2013-03-25Handle oveflow in O(U)String::toInt() functionsZolnai Tamás
Return 0 when overflow. The base idea in unsigned case is checking wheather (Max-nDigit)/nRadix < n But for efficency, take out nDiv = Max/nRadix from loop and corrigate it with -1 if needed. In signed case use minimum value if the number is negativ. Change-Id: I5b77580adbf12421b6c4b785ba9bc2a080accba2 Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
2013-03-23coverity#704247 Logically dead codeJulien Nabet
Change-Id: Iaefddeb816d36d4a07234d903fafab3d6b83e1d2 Reviewed-on: https://gerrit.libreoffice.org/2952 Reviewed-by: Thomas Arnhold <thomas@arnhold.org> Reviewed-by: Thorsten Behrens <tbehrens@suse.com> Tested-by: Thorsten Behrens <tbehrens@suse.com>
2013-02-22Bin pointless single-child directory levelTor Lillqvist
Change-Id: I03de46fb6c095bb176fd25fc5f803be6d2d89bcf