GithubHelp home page GithubHelp logo

xparq / cstdstring Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 5.0 121 KB

Joe O'Leary's excellent drop-in CString replacement, facelifted for contemporary C++

License: Other

C++ 99.09% Batchfile 0.50% C 0.26% Shell 0.15%

cstdstring's People

Contributors

xparq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cstdstring's Issues

constexpr

Hello
Is there a version that already support constexpr?

Not an issue, just a thank you

I just stumbled across this. It's kind of you to bring this up to spec. I still keep my own personal version on hand that I occasionally use from time with gcc and VS2022 on W4 and Standard C++17. But I never updated my code-project article. Shame on me.

Incidentally the email address in the header file is still my current email if anyone ever needs to email me.

-Joe

Compiling under VS2017

I am trying to compile CStdString.h under VS2017, but I get an error.
Inside
HRESULT StreamSave(IStream* pStream) const
I have to change
else if ( empty() )
to
else if ( this->empty() )

Memory leak in Format(...) function

If the formatted string is bigger than 512 characters, the Format(...) routine will leak memory on Windows Unicode builds. This is, because pBuf is not freed from the previous iteration in the following loop:

void FormatV(const CT* szFormat, va_list argList)
(...)
		do	
		{
			// Grow more than linearly (e.g. 512, 1536, 3072, etc)

			nChars			+= ((nTry+1) * FMT_BLOCK_SIZE);
//!!alloca is unavailable/problematic in many environments:
//!!			pBuf			= reinterpret_cast<CT*>(_alloca(sizeof(CT)*nChars));

                        /***** This free() is missing *********/
			if (pBuf) free(pBuf);
			
			pBuf			= reinterpret_cast<CT*>(malloc(sizeof(CT)*nChars));
			if (!pBuf) throw(std::bad_alloc());
			nUsed			= ssvsprintf(pBuf, nChars-1, szFormat, argList);

			// Ensure proper NULL termination.

			nActual			= nUsed == -1 ? nChars-1 : SSMIN(nUsed, nChars-1);
			pBuf[nActual]= '\0';


		} while ( nUsed < 0 && nTry++ < MAX_FMT_TRIES );

Compiling under GCC (Ubuntu on 20.04)

I am trying to compile CStdString.h under GCC 9.3.0, but I get many warnings "warning: statement has no effect [-Wunused-value]"
Changing
#define UNUSED(x) x
to
#define UNUSED(x) (void)x
removes many of them; however UNUSED() should be applied also to the various
szCvt;
empty instructions in ssadd and ssasn.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.