Skip to content

Commit

Permalink
Fix array out of bound errors as detected by valgrind and uninitializ…
Browse files Browse the repository at this point in the history
…ed memory reads.
  • Loading branch information
Soeren Sonnenburg committed Apr 20, 2011
1 parent 9b62354 commit 76bf7f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/libshogun/kernel/OligoStringKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ void COligoStringKernel::getExpFunctionCache(uint32_t sequence_length)
gauss_table=new float64_t[sequence_length];

gauss_table[0] = 1;
for (uint32_t i = 1; i < sequence_length - 1; i++)
gauss_table[i] = exp((-1 / (CMath::sq(width))) * CMath::sq(i));
for (uint32_t i = 1; i < sequence_length; i++)
gauss_table[i] = exp((-1.0 / (CMath::sq(width))) * CMath::sq((float64_t) i));

gauss_table_len=sequence_length;
}
Expand All @@ -162,7 +162,7 @@ float64_t COligoStringKernel::kernelOligoFast(
uint32_t x_size = x.size();
uint32_t y_size = y.size();

while ((uint32_t) i1 < x_size && (uint32_t) i2 < y_size)
while ((uint32_t) i1 + 1 < x_size && (uint32_t) i2 + 1 < y_size)
{
if (x[i1].second == y[i2].second)
{
Expand Down Expand Up @@ -197,10 +197,8 @@ float64_t COligoStringKernel::kernelOligoFast(
}
else if (y[i2].second == y[i2 + 1].second)
{
while(y[i2++].second == y[i2].second)
{
;
}
while (y[i2].second == y[i2+1].second)
i2++;
++i1;
c1 = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libshogun/kernel/OligoStringKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class COligoStringKernel : public CStringKernel<char>
{
public:
/** default constructor */
COligoStringKernel(void);
COligoStringKernel();

/** Constructor
* @param cache_size cache size for kernel
Expand Down

0 comments on commit 76bf7f7

Please sign in to comment.