Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly initialize event_pubkeys #510

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/komodo_structs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ std::ostream& operator<<(std::ostream& os, const event& in)
* @param pos the starting position (will advance)
* @param data_len full length of data
*/
event_pubkeys::event_pubkeys(uint8_t* data, long& pos, long data_len, int32_t height) : event(EVENT_PUBKEYS, height)
event_pubkeys::event_pubkeys(uint8_t* data, long& pos, long data_len, int32_t height) : event_pubkeys(height)
{
num = data[pos++];
if (num > 64)
throw parse_error("Illegal number of keys: " + std::to_string(num));
mem_nread(pubkeys, num, data, pos, data_len);
}

event_pubkeys::event_pubkeys(FILE* fp, int32_t height) : event(EVENT_PUBKEYS, height)
event_pubkeys::event_pubkeys(FILE* fp, int32_t height) : event_pubkeys(height)
{
num = fgetc(fp);
if ( fread(pubkeys,33,num,fp) != num )
Expand All @@ -160,7 +160,7 @@ std::ostream& operator<<(std::ostream& os, const event_pubkeys& in)
return os;
}

event_rewind::event_rewind(uint8_t *data, long &pos, long data_len, int32_t height) : event(EVENT_REWIND, height)
event_rewind::event_rewind(uint8_t *data, long &pos, long data_len, int32_t height) : event_rewind(height)
{
// nothing to do
}
Expand All @@ -171,11 +171,10 @@ std::ostream& operator<<(std::ostream& os, const event_rewind& in)
return os;
}

event_notarized::event_notarized(uint8_t *data, long &pos, long data_len, int32_t height, const char* _dest, bool includeMoM)
: event(EVENT_NOTARIZED, height), MoMdepth(0)
event_notarized::event_notarized(uint8_t *data, long &pos, long data_len, int32_t height,
const char* _dest, bool includeMoM)
: event_notarized(height, dest)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems 'dest' is not initialised yet (maybe _dest was supposed)

{
strncpy(this->dest, _dest, sizeof(this->dest)-1);
this->dest[sizeof(this->dest)-1] = 0;
MoM.SetNull();
mem_read(this->notarizedheight, data, pos, data_len);
mem_read(this->blockhash, data, pos, data_len);
Expand All @@ -188,10 +187,8 @@ event_notarized::event_notarized(uint8_t *data, long &pos, long data_len, int32_
}

event_notarized::event_notarized(FILE* fp, int32_t height, const char* _dest, bool includeMoM)
: event(EVENT_NOTARIZED, height), MoMdepth(0)
: event_notarized(height, dest)
Copy link
Collaborator

@dimxy dimxy Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here: it seems 'dest' is not initialised yet
(interesting that my g++ version does not show this as 'warning: field is uninitialized when used here'. It would show this warning only if I made this 'dest' field as int)

{
strncpy(this->dest, _dest, sizeof(this->dest)-1);
this->dest[sizeof(this->dest)-1] = 0;
MoM.SetNull();
if ( fread(&notarizedheight,1,sizeof(notarizedheight),fp) != sizeof(notarizedheight) )
throw parse_error("Invalid notarization height");
Expand Down Expand Up @@ -223,15 +220,15 @@ std::ostream& operator<<(std::ostream& os, const event_notarized& in)
return os;
}

event_u::event_u(uint8_t *data, long &pos, long data_len, int32_t height) : event(EVENT_U, height)
event_u::event_u(uint8_t *data, long &pos, long data_len, int32_t height) : event_u(height)
{
mem_read(this->n, data, pos, data_len);
mem_read(this->nid, data, pos, data_len);
mem_read(this->mask, data, pos, data_len);
mem_read(this->hash, data, pos, data_len);
}

event_u::event_u(FILE *fp, int32_t height) : event(EVENT_U, height)
event_u::event_u(FILE *fp, int32_t height) : event_u(height)
{
if (fread(&n, 1, sizeof(n), fp) != sizeof(n))
throw parse_error("Unable to read n of event U from file");
Expand All @@ -253,14 +250,16 @@ std::ostream& operator<<(std::ostream& os, const event_u& in)
return os;
}

event_kmdheight::event_kmdheight(uint8_t* data, long &pos, long data_len, int32_t height, bool includeTimestamp) : event(EVENT_KMDHEIGHT, height)
event_kmdheight::event_kmdheight(uint8_t* data, long &pos, long data_len, int32_t height,
bool includeTimestamp) : event_kmdheight(height)
{
mem_read(this->kheight, data, pos, data_len);
if (includeTimestamp)
mem_read(this->timestamp, data, pos, data_len);
}

event_kmdheight::event_kmdheight(FILE *fp, int32_t height, bool includeTimestamp) : event(EVENT_KMDHEIGHT, height)
event_kmdheight::event_kmdheight(FILE *fp, int32_t height, bool includeTimestamp)
: event_kmdheight(height)
{
if ( fread(&kheight,1,sizeof(kheight),fp) != sizeof(kheight) )
throw parse_error("Unable to parse KMD height");
Expand All @@ -280,7 +279,8 @@ std::ostream& operator<<(std::ostream& os, const event_kmdheight& in)
return os;
}

event_opreturn::event_opreturn(uint8_t *data, long &pos, long data_len, int32_t height) : event(EVENT_OPRETURN, height)
event_opreturn::event_opreturn(uint8_t *data, long &pos, long data_len, int32_t height)
: event_opreturn(height)
{
mem_read(this->txid, data, pos, data_len);
mem_read(this->vout, data, pos, data_len);
Expand All @@ -294,7 +294,7 @@ event_opreturn::event_opreturn(uint8_t *data, long &pos, long data_len, int32_t
}
}

event_opreturn::event_opreturn(FILE* fp, int32_t height) : event(EVENT_OPRETURN, height)
event_opreturn::event_opreturn(FILE* fp, int32_t height) : event_opreturn(height)
{
if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) )
throw parse_error("Unable to parse txid of opreturn record");
Expand Down Expand Up @@ -322,7 +322,8 @@ std::ostream& operator<<(std::ostream& os, const event_opreturn& in)
return os;
}

event_pricefeed::event_pricefeed(uint8_t *data, long &pos, long data_len, int32_t height) : event(EVENT_PRICEFEED, height)
event_pricefeed::event_pricefeed(uint8_t *data, long &pos, long data_len, int32_t height)
: event_pricefeed(height)
{
mem_read(this->num, data, pos, data_len);
// we're only interested if there are 35 prices.
Expand All @@ -333,7 +334,8 @@ event_pricefeed::event_pricefeed(uint8_t *data, long &pos, long data_len, int32_
pos += num * sizeof(uint32_t);
}

event_pricefeed::event_pricefeed(FILE* fp, int32_t height) : event(EVENT_PRICEFEED, height)
event_pricefeed::event_pricefeed(FILE* fp, int32_t height)
: event_pricefeed(height)
{
num = fgetc(fp);
if ( num * sizeof(uint32_t) <= sizeof(prices) && fread(prices,sizeof(uint32_t),num,fp) != num )
Expand Down