diff options
| author | 2018-04-22 21:43:24 -0400 | |
|---|---|---|
| committer | 2018-04-22 21:43:24 -0400 | |
| commit | bebefa0c25342a23f1ba0ab6796b8c44dae62b14 (patch) | |
| tree | 06fd65c34ab1a9dc994614f9d7bf9b2f0e9a3f3e /src/modules | |
| parent | Remove unused/useless code (diff) | |
| download | KVIrc-bebefa0c25342a23f1ba0ab6796b8c44dae62b14.tar.gz KVIrc-bebefa0c25342a23f1ba0ab6796b8c44dae62b14.tar.bz2 KVIrc-bebefa0c25342a23f1ba0ab6796b8c44dae62b14.zip | |
Fix undefined behavior involving lifetime of temporaries
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/objects/KvsObject_file.cpp | 12 | ||||
| -rw-r--r-- | src/modules/perlcore/libkviperlcore.cpp | 11 |
2 files changed, 10 insertions, 13 deletions
diff --git a/src/modules/objects/KvsObject_file.cpp b/src/modules/objects/KvsObject_file.cpp index 449e32fbc..2b2e10746 100644 --- a/src/modules/objects/KvsObject_file.cpp +++ b/src/modules/objects/KvsObject_file.cpp @@ -335,8 +335,8 @@ KVSO_CLASS_FUNCTION(file, putch) KVSO_PARAMETERS_END(c) if(szChar.length() > 1) c->warning(__tr2qs_ctx("Argument too long, using only first char", "objects")); - const char * ch = szChar.toUtf8().data(); - if(!m_pFile->putChar(ch[0])) + QByteArray szCh = szChar.toUtf8(); + if(!m_pFile->putChar(szCh[0])) c->warning(__tr2qs_ctx("Write error occurred!", "objects")); return true; } @@ -375,8 +375,8 @@ KVSO_CLASS_FUNCTION(file, unGetch) KVSO_PARAMETERS_END(c) if(szChar.length() > 1) c->warning(__tr2qs_ctx("Argument too long, using only the first char", "objects")); - const char * ch = szChar.toUtf8().data(); - m_pFile->ungetChar(ch[0]); + QByteArray szCh = szChar.toUtf8(); + m_pFile->ungetChar(szCh[0]); return true; } @@ -554,8 +554,8 @@ KVSO_CLASS_FUNCTION(file, writeBlock) } QString szBlock; pVariantData->asString(szBlock); - const char * block = szBlock.toUtf8().data(); - int rlen = m_pFile->write(block, uLen); + QByteArray block = szBlock.toUtf8(); + int rlen = m_pFile->write(block.data(), uLen); c->returnValue()->setInteger(rlen); } } diff --git a/src/modules/perlcore/libkviperlcore.cpp b/src/modules/perlcore/libkviperlcore.cpp index fcd66152b..3fdd42def 100644 --- a/src/modules/perlcore/libkviperlcore.cpp +++ b/src/modules/perlcore/libkviperlcore.cpp @@ -270,13 +270,10 @@ bool KviPerlInterpreter::execute( int idx = 0; for(auto tmp : args) { - const char * val = tmp.toUtf8().data(); - if(val) - { - pArg = newSVpv(val, tmp.length()); - if(!av_store(pArgs, idx, pArg)) - SvREFCNT_dec(pArg); - } + QByteArray szVal = tmp.toUtf8(); + pArg = newSVpv(szVal.data(), tmp.length()); + if(!av_store(pArgs, idx, pArg)) + SvREFCNT_dec(pArg); idx++; } } |
