Skip to content

Commit

Permalink
Fix Code memory freeing and various fuzztest bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mhosken committed Jul 6, 2015
1 parent 08735d0 commit 4e232ad
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
41 changes: 22 additions & 19 deletions src/Bidi.cpp
Expand Up @@ -571,35 +571,38 @@ void processParens(Slot *s, Segment *seg, uint8 aMirror, int level, BracketPairS
mask |= 2;
}
}
for (p = stack.start(); p; p =p->next()) // walk the stack
if (stack.size())
{
if (p->close() && p->mask())
for (p = stack.start(); p; p =p->next()) // walk the stack
{
int dir = (level & 1) + 1;
if (p->mask() & dir)
{ }
else if (p->mask() & (1 << (~level & 1))) // if inside has strong other embedding
if (p->close() && p->mask())
{
int ldir = p->before();
if ((p->before() == OPP || p->before() == CPP) && p->prev())
int dir = (level & 1) + 1;
if (p->mask() & dir)
{ }
else if (p->mask() & (1 << (~level & 1))) // if inside has strong other embedding
{
for (BracketPair *q = p->prev(); q; q = q->prev())
int ldir = p->before();
if ((p->before() == OPP || p->before() == CPP) && p->prev())
{
ldir = q->open()->getBidiClass();
if (ldir < 3) break;
ldir = q->before();
if (ldir < 3) break;
for (BracketPair *q = p->prev(); q; q = q->prev())
{
ldir = q->open()->getBidiClass();
if (ldir < 3) break;
ldir = q->before();
if (ldir < 3) break;
}
if (ldir > 2) ldir = 0;
}
if (ldir > 2) ldir = 0;
if (ldir > 0 && (ldir - 1) != (level & 1)) // is dir given opp. to level dir (ldir == R or L)
dir = (~level & 1) + 1;
}
if (ldir > 0 && (ldir - 1) != (level & 1)) // is dir given opp. to level dir (ldir == R or L)
dir = (~level & 1) + 1;
p->open()->setBidiClass(dir);
p->close()->setBidiClass(dir);
}
p->open()->setBidiClass(dir);
p->close()->setBidiClass(dir);
}
stack.clear();
}
stack.clear();
}

int GetDeferredNeutrals(int action, int level)
Expand Down
3 changes: 2 additions & 1 deletion src/Code.cpp
Expand Up @@ -611,7 +611,8 @@ void Machine::Code::decoder::analysis::set_changed(const int index) throw() {

void Machine::Code::release_buffers() throw()
{
free(_code);
if (_own)
free(_code);
_code = 0;
_data = 0;
_own = false;
Expand Down
9 changes: 5 additions & 4 deletions src/Pass.cpp
Expand Up @@ -74,9 +74,9 @@ Pass::~Pass()
free(m_states);
free(m_ruleMap);

delete [] m_rules;
delete [] m_codes;
free(m_progs);
if (m_rules) delete [] m_rules;
if (m_codes) delete [] m_codes;
if (m_progs) free(m_progs);
}

bool Pass::readPass(const byte * const pass_start, size_t pass_length, size_t subtable_base, GR_MAYBE_UNUSED Face & face, passtype pt, Error &e)
Expand Down Expand Up @@ -244,9 +244,10 @@ bool Pass::readRules(const byte * rule_map, const size_t num_entries,
}

// Shrink the program pool
ptrdiff_t const delta = m_progs - static_cast<byte *>(realloc(m_progs, prog_pool_free - m_progs));
ptrdiff_t const delta = static_cast<byte *>(realloc(m_progs, prog_pool_free - m_progs)) - m_progs;
if (delta)
{
m_progs += delta;
for (Code * c = m_codes, * const ce = c + m_numRules*2; c != ce; ++c)
{
c->externalProgramMoved(delta);
Expand Down
4 changes: 2 additions & 2 deletions tests/fuzz-tests/CMakeLists.txt
Expand Up @@ -22,9 +22,9 @@ foreach (tfile IN LISTS tfiles)
add_custom_command(TARGET fuzztest PRE_BUILD COMMAND echo ${fname})
set(lastfontname ${fname})
endif(NOT lastfontname EQUAL fname)
add_custom_command(TARGET fuzztest PRE_BUILD COMMAND ${PROJECT_SOURCE_DIR}/../fuzztest ARGS -l fuzzregress-${fname}-${textname}-${tname}.log -f ${PROJECT_SOURCE_DIR}/../fonts/${fname}.ttf -q ${noasan} --include=required,graphite --exclude==fontdir,opentype,volt,advtypo,post --input=${PROJECT_SOURCE_DIR}/${fname}/${textname}/${tname} -- ../comparerenderer/comparerenderer -q -s 12 -n -f {} -t ${PROJECT_SOURCE_DIR}/../texts/${textname}.txt)
add_custom_command(TARGET fuzztest PRE_BUILD COMMAND ${PROJECT_SOURCE_DIR}/../fuzztest ARGS -l fuzzregress-${fname}-${textname}-${tname}.log -f ${PROJECT_SOURCE_DIR}/../fonts/${fname}.ttf -q ${noasan} --include=required,graphite --exclude==fontdir,opentype,volt,advtypo,post -V -k --input=${PROJECT_SOURCE_DIR}/${fname}/${textname}/${tname} -- ../comparerenderer/comparerenderer -q -s 12 -n -f {} -t ${PROJECT_SOURCE_DIR}/../texts/${textname}.txt)
add_custom_command(TARGET fuzztest POST_BUILD COMMAND perl ARGS -e 'print "$$ARGV[0] Failed\\n" if\(-s $$ARGV[0]\)' fuzzregress-${fname}-${textname}-${tname}.log)
add_custom_command(TARGET fuzztest PRE_BUILD COMMAND ${PROJECT_SOURCE_DIR}/../fuzztest ARGS -l fuzzregress-demand-${fname}-${textname}-${tname}.log -f ${PROJECT_SOURCE_DIR}/../fonts/${fname}.ttf -q ${noasan} --include=required,graphite --exclude==fontdir,opentype,volt,advtypo,post --input=${PROJECT_SOURCE_DIR}/${fname}/${textname}/${tname} -- ../comparerenderer/comparerenderer --demand -q -s 12 -n -f {} -t ${PROJECT_SOURCE_DIR}/../texts/${textname}.txt)
add_custom_command(TARGET fuzztest PRE_BUILD COMMAND ${PROJECT_SOURCE_DIR}/../fuzztest ARGS -l fuzzregress-demand-${fname}-${textname}-${tname}.log -f ${PROJECT_SOURCE_DIR}/../fonts/${fname}.ttf -q ${noasan} --include=required,graphite --exclude==fontdir,opentype,volt,advtypo,post -V -k --input=${PROJECT_SOURCE_DIR}/${fname}/${textname}/${tname} -- ../comparerenderer/comparerenderer --demand -q -s 12 -n -f {} -t ${PROJECT_SOURCE_DIR}/../texts/${textname}.txt)
add_custom_command(TARGET fuzztest POST_BUILD COMMAND perl ARGS -e 'print "$$ARGV[0] Failed\\n" if\(-s $$ARGV[0]\)' fuzzregress-demand-${fname}-${textname}-${tname}-demand.log)
endforeach(tfile)

4 changes: 3 additions & 1 deletion tests/fuzztest
Expand Up @@ -212,6 +212,7 @@ parser.add_option("-P","--passes",type='int', default=0, help='Run this many pas
parser.add_option("-j","--jobs",type='int', default=None, help='Number of subprocesses to run in parallel (default: cpu count)')
parser.add_option("-r","--random",help="Seed the random number generator with the given string")
parser.add_option("--valgrind",action="store_true",help="Run tests with valgrind and report errors")
parser.add_option("-k","--keep",action="store_true",help="Keep going. Don't return error status")
testset = OptionGroup(parser, 'Test sets',
'Explicitly specify which tables to include or exclude from testing. '
'By default all tables (including the font directory) are included.'
Expand Down Expand Up @@ -289,4 +290,5 @@ if __name__ == '__main__':
sys.exit(exitrv)
if opts.status :
sys.stdout.write("Finished at {0}\n".format(time.ctime()))
sys.exit(exitrv)
if not opts.keep :
sys.exit(exitrv)

0 comments on commit 4e232ad

Please sign in to comment.