summaryrefslogtreecommitdiff
path: root/idlc
diff options
context:
space:
mode:
authorMatthias Huetsch [mhu] <matthias.huetsch@oracle.com>2010-11-25 14:24:19 +0100
committerMatthias Huetsch [mhu] <matthias.huetsch@oracle.com>2010-11-25 14:24:19 +0100
commit3864bd15f801f6fb40f46f9eba23cae288733eaa (patch)
treebdfaafbf2c18641bf1baf1e315c3820948231a0c /idlc
parent7f77721e5a3876ef311841edb21680b4af15a9e7 (diff)
#i115784# idlc: fix memory errors uncovered by valgrind and other tools.
Diffstat (limited to 'idlc')
-rw-r--r--idlc/source/astexpression.cxx21
-rw-r--r--idlc/source/options.cxx81
-rw-r--r--idlc/source/preproc/eval.c15
-rw-r--r--idlc/source/preproc/lex.c10
-rw-r--r--idlc/source/preproc/unix.c1
5 files changed, 64 insertions, 64 deletions
diff --git a/idlc/source/astexpression.cxx b/idlc/source/astexpression.cxx
index 707629c1d..e051de2c7 100644
--- a/idlc/source/astexpression.cxx
+++ b/idlc/source/astexpression.cxx
@@ -27,6 +27,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_idlc.hxx"
+
#include <idlc/astexpression.hxx>
#include <idlc/astconstant.hxx>
#include <idlc/astscope.hxx>
@@ -34,6 +35,7 @@
#include <limits.h>
#include <float.h>
+#include <memory> // auto_ptr<>
#undef MAXCHAR
#define MAXCHAR 127
@@ -927,7 +929,6 @@ AstExprValue* AstExpression::eval_internal(EvalKind ek)
AstExprValue* AstExpression::eval_bin_op(EvalKind ek)
{
- AstExprValue *retval = NULL;
ExprType eType = ET_double;
if ( m_combOperator == EC_mod )
@@ -950,7 +951,7 @@ AstExprValue* AstExpression::eval_bin_op(EvalKind ek)
if (m_subExpr2->getExprValue() == NULL)
return NULL;
- retval = new AstExprValue();
+ std::auto_ptr< AstExprValue > retval(new AstExprValue());
retval->et = eType;
switch (m_combOperator)
@@ -971,20 +972,18 @@ AstExprValue* AstExpression::eval_bin_op(EvalKind ek)
break;
case EC_div:
if (m_subExpr2->getExprValue()->u.dval == 0.0)
- return NULL;
+ return NULL;
retval->u.dval = m_subExpr1->getExprValue()->u.dval / m_subExpr2->getExprValue()->u.dval;
break;
default:
return NULL;
}
- return retval;
+ return retval.release();
}
AstExprValue* AstExpression::eval_bit_op(EvalKind ek)
{
- AstExprValue *retval = NULL;
-
if (ek != EK_const && ek != EK_positive_int)
return NULL;
if (m_subExpr1 == NULL || m_subExpr2 == NULL)
@@ -1002,7 +1001,7 @@ AstExprValue* AstExpression::eval_bit_op(EvalKind ek)
if (m_subExpr2->getExprValue() == NULL)
return NULL;
- retval = new AstExprValue;
+ std::auto_ptr< AstExprValue > retval(new AstExprValue());
retval->et = ET_long;
switch (m_combOperator)
@@ -1026,13 +1025,11 @@ AstExprValue* AstExpression::eval_bit_op(EvalKind ek)
return NULL;
}
- return retval;
+ return retval.release();
}
AstExprValue* AstExpression::eval_un_op(EvalKind ek)
{
- AstExprValue *retval = NULL;
-
if (m_exprValue != NULL)
return m_exprValue;
@@ -1047,7 +1044,7 @@ AstExprValue* AstExpression::eval_un_op(EvalKind ek)
if (m_subExpr1->getExprValue() == NULL)
return NULL;
- retval = new AstExprValue();
+ std::auto_ptr< AstExprValue > retval(new AstExprValue());
retval->et = ET_double;
switch (m_combOperator)
@@ -1068,7 +1065,7 @@ AstExprValue* AstExpression::eval_un_op(EvalKind ek)
return NULL;
}
- return retval;
+ return retval.release();
}
AstExprValue* AstExpression::eval_symbol(EvalKind ek)
diff --git a/idlc/source/options.cxx b/idlc/source/options.cxx
index df53b2186..a3f2acc3b 100644
--- a/idlc/source/options.cxx
+++ b/idlc/source/options.cxx
@@ -28,9 +28,10 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_idlc.hxx"
+#include "idlc/options.hxx"
+
#include <stdio.h>
-#include /*MSVC trouble: <cstring>*/ <string.h>
-#include <idlc/options.hxx>
+#include <string.h>
using namespace rtl;
@@ -226,7 +227,7 @@ sal_Bool Options::initOptions(int ac, char* av[], sal_Bool bCmdFile)
exit(0);
}
case 's':
- if (/*MSVC trouble: std::*/strcmp(&av[j][2], "tdin") == 0)
+ if (strcmp(&av[j][2], "tdin") == 0)
{
m_stdin = true;
break;
@@ -246,53 +247,49 @@ sal_Bool Options::initOptions(int ac, char* av[], sal_Bool bCmdFile)
ret = sal_False;
} else
{
- int rargc=0;
- char* rargv[512];
- char buffer[512]="";
+ std::vector< std::string > args;
+
+ std::string buffer;
+ buffer.reserve(256);
- int i=0;
- int found = 0;
- char c;
- while ( fscanf(cmdFile, "%c", &c) != EOF )
+ bool quoted = false;
+ int c = EOF;
+ while ((c = fgetc(cmdFile)) != EOF)
{
- if (c=='\"') {
- if (found) {
- found=0;
- } else {
- found=1;
- continue;
- }
- } else {
- if (c!=13 && c!=10) {
- if (found || c!=' ') {
- buffer[i++]=c;
- continue;
+ switch(c)
+ {
+ case '\"':
+ quoted = !quoted;
+ break;
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ if (!quoted)
+ {
+ if (!buffer.empty())
+ {
+ // append current argument.
+ args.push_back(buffer);
+ buffer.clear();
}
+ break;
}
- if (i==0)
- continue;
+ default:
+ // quoted white-space fall through
+ buffer.push_back(sal::static_int_cast<char>(c));
+ break;
}
- buffer[i]='\0';
- found=0;
- i=0;
- rargv[rargc]= strdup(buffer);
- rargc++;
- buffer[0]='\0';
}
- if (buffer[0] != '\0') {
- buffer[i]='\0';
- rargv[rargc]= strdup(buffer);
- rargc++;
- }
- fclose(cmdFile);
-
- ret = initOptions(rargc, rargv, bCmdFile);
-
- long ii = 0;
- for (ii=0; ii < rargc; ii++)
+ if (!buffer.empty())
{
- free(rargv[ii]);
+ // append unterminated argument.
+ args.push_back(buffer);
+ buffer.clear();
}
+ (void) fclose(cmdFile);
+
+ ret = initOptions(args.size(), args.data(), bCmdFile);
}
} else
{
diff --git a/idlc/source/preproc/eval.c b/idlc/source/preproc/eval.c
index cbac1d79c..96dc2342d 100644
--- a/idlc/source/preproc/eval.c
+++ b/idlc/source/preproc/eval.c
@@ -24,9 +24,11 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
+
+#include "cpp.h"
+
#include <stdlib.h>
#include <string.h>
-#include "cpp.h"
#define NSTAK 32
#define SGN 0
@@ -736,10 +738,10 @@ struct value
}
else
{
- static char cvcon[]
- = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\";
+ static char cvcon[] = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\";
+ static int cvlen = sizeof(cvcon) - 1;
- for (i = 0; i < (int)sizeof(cvcon); i += 2)
+ for (i = 0; i < cvlen; i += 2)
{
if (*p == cvcon[i])
{
@@ -748,9 +750,8 @@ struct value
}
}
p += 1;
- if (i >= (int)sizeof(cvcon))
- error(WARNING,
- "Undefined escape in character constant");
+ if (i >= cvlen)
+ error(WARNING,"Undefined escape in character constant");
}
}
else
diff --git a/idlc/source/preproc/lex.c b/idlc/source/preproc/lex.c
index d88a475b3..87d9e6c8d 100644
--- a/idlc/source/preproc/lex.c
+++ b/idlc/source/preproc/lex.c
@@ -290,7 +290,7 @@ void
bigfsm[j][fp->state] = (short) nstate;
continue;
case C_ALPH:
- for (j = 0; j <= 256; j++)
+ for (j = 0; j < 256; j++)
if (('a' <= j && j <= 'z') || ('A' <= j && j <= 'Z')
|| j == '_')
bigfsm[j][fp->state] = (short) nstate;
@@ -687,9 +687,13 @@ void
if (s->fd >= 0)
{
- close(s->fd);
- dofree(s->inb);
+ (void) close(s->fd);
+ dofree(s->filename);
}
+
+ if (s->inb)
+ dofree(s->inb);
+
cursource = s->next;
dofree(s);
}
diff --git a/idlc/source/preproc/unix.c b/idlc/source/preproc/unix.c
index fae43597f..906dca796 100644
--- a/idlc/source/preproc/unix.c
+++ b/idlc/source/preproc/unix.c
@@ -92,6 +92,7 @@ void
maketokenrow(3, &tr);
gettokens(&tr, 1);
doadefine(&tr, c);
+ dofree(tr.bp); tr.bp = 0;
unsetsource();
break;