mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
fix some more overflow panics
This commit is contained in:
parent
7cc06bddee
commit
66d568a65f
3 changed files with 3 additions and 4 deletions
|
|
@ -62,7 +62,6 @@ impl Parse for GameEventMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
dbg!(state.event_definitions.len());
|
|
||||||
return Err(ParseError::MalformedGameEvent(GameEventError::UnknownType(
|
return Err(ParseError::MalformedGameEvent(GameEventError::UnknownType(
|
||||||
event_type,
|
event_type,
|
||||||
)));
|
)));
|
||||||
|
|
|
||||||
|
|
@ -235,11 +235,11 @@ impl PacketEntitiesMessage {
|
||||||
send_table: &SendTable,
|
send_table: &SendTable,
|
||||||
props: &mut Vec<SendProp>,
|
props: &mut Vec<SendProp>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut index = -1;
|
let mut index: i32 = -1;
|
||||||
|
|
||||||
while stream.read()? {
|
while stream.read()? {
|
||||||
let diff: u32 = read_bit_var(stream)?;
|
let diff: u32 = read_bit_var(stream)?;
|
||||||
index += (diff as i32) + 1;
|
index = index.saturating_add(diff as i32).saturating_add(1);
|
||||||
|
|
||||||
match send_table.flattened_props.get(index as usize) {
|
match send_table.flattened_props.get(index as usize) {
|
||||||
Some(definition) => {
|
Some(definition) => {
|
||||||
|
|
|
||||||
|
|
@ -483,7 +483,7 @@ impl SendPropValue {
|
||||||
.ok_or(MalformedSendPropDefinitionError::UnsizedFloat)?;
|
.ok_or(MalformedSendPropDefinitionError::UnsizedFloat)?;
|
||||||
let raw: u32 = stream.read_int(bit_count as usize)?;
|
let raw: u32 = stream.read_int(bit_count as usize)?;
|
||||||
// is this -1 correct?, it is consistent with the js version but seems weird
|
// is this -1 correct?, it is consistent with the js version but seems weird
|
||||||
let percentage = (raw as f32) / ((1 << bit_count) as f32 - 1.0);
|
let percentage = (raw as f32) / ((1i32.wrapping_shl(bit_count)) as f32 - 1.0);
|
||||||
Ok(low + ((high - low) * percentage))
|
Ok(low + ((high - low) * percentage))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue