Skip to content

Commit

Permalink
Q. Does || have the same semantics in C as in Perl? A. No, idiot. BTW…
Browse files Browse the repository at this point in the history
…, here's a corrupt heap. Enjoy your day!
  • Loading branch information
jnthn committed Feb 13, 2012
1 parent dfdba67 commit bf0a0d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/6model/reprs/P6opaque.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "../sixmodelobject.h"
#include "P6opaque.h"

#define MAX(x, y) ((y) > (x) ? (y) : (x))

/* This representation's function pointer table. */
static REPROps *this_repr;

Expand Down Expand Up @@ -968,7 +970,7 @@ static void deserialize_repr_data(PARROT_INTERP, STable *st, SerializationReader

repr_data->num_attributes = reader->read_int(interp, reader);

repr_data->flattened_stables = mem_sys_allocate((repr_data->num_attributes || 1) * sizeof(STable *));
repr_data->flattened_stables = mem_sys_allocate(MAX(repr_data->num_attributes, 1) * sizeof(STable *));
for (i = 0; i < repr_data->num_attributes; i++)
if (reader->read_int(interp, reader))
repr_data->flattened_stables[i] = reader->read_stable_ref(interp, reader);
Expand All @@ -978,7 +980,7 @@ static void deserialize_repr_data(PARROT_INTERP, STable *st, SerializationReader
repr_data->mi = reader->read_int(interp, reader);

if (reader->read_int(interp, reader)) {
repr_data->auto_viv_values = mem_sys_allocate((repr_data->num_attributes || 1) * sizeof(PMC *));
repr_data->auto_viv_values = mem_sys_allocate(MAX(repr_data->num_attributes, 1) * sizeof(PMC *));
for (i = 0; i < repr_data->num_attributes; i++)
repr_data->auto_viv_values[i] = reader->read_ref(interp, reader);
}
Expand All @@ -988,7 +990,7 @@ static void deserialize_repr_data(PARROT_INTERP, STable *st, SerializationReader
repr_data->unbox_str_slot = reader->read_int(interp, reader);

if (reader->read_int(interp, reader)) {
repr_data->unbox_slots = mem_sys_allocate((repr_data->num_attributes || 1) * sizeof(P6opaqueBoxedTypeMap));
repr_data->unbox_slots = mem_sys_allocate(MAX(repr_data->num_attributes, 1) * sizeof(P6opaqueBoxedTypeMap));
for (i = 0; i < repr_data->num_attributes; i++) {
repr_data->unbox_slots[i].repr_id = reader->read_int(interp, reader);
repr_data->unbox_slots[i].slot = reader->read_int(interp, reader);
Expand All @@ -1004,8 +1006,8 @@ static void deserialize_repr_data(PARROT_INTERP, STable *st, SerializationReader

/* Re-calculate the remaining info, which is platform specific or
* derived information. */
repr_data->attribute_offsets = mem_sys_allocate((repr_data->num_attributes || 1) * sizeof(INTVAL));
repr_data->gc_pmc_mark_offsets = mem_sys_allocate((repr_data->num_attributes || 1) * sizeof(INTVAL));
repr_data->attribute_offsets = mem_sys_allocate(MAX(repr_data->num_attributes, 1) * sizeof(INTVAL));
repr_data->gc_pmc_mark_offsets = mem_sys_allocate(MAX(repr_data->num_attributes, 1) * sizeof(INTVAL));
repr_data->initialize_slots = mem_sys_allocate((repr_data->num_attributes + 1) * sizeof(INTVAL));
repr_data->gc_mark_slots = mem_sys_allocate((repr_data->num_attributes + 1) * sizeof(INTVAL));
repr_data->gc_cleanup_slots = mem_sys_allocate((repr_data->num_attributes + 1) * sizeof(INTVAL));
Expand Down
6 changes: 4 additions & 2 deletions src/6model/serialization.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "pmc_nqplexinfo.h"
#include "pmc/pmc_sub.h"

#define MAX(x, y) ((y) > (x) ? (y) : (x))

/* Version of the serialization format that we are currently at. */
#define CURRENT_VERSION 1

Expand Down Expand Up @@ -774,11 +776,11 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
writer->root.dependencies_table = mem_sys_allocate(writer->dependencies_table_alloc);
writer->stables_table_alloc = STABLES_TABLE_ENTRY_SIZE * STABLES_TABLE_ENTRIES_GUESS;
writer->root.stables_table = mem_sys_allocate(writer->stables_table_alloc);
writer->objects_table_alloc = OBJECTS_TABLE_ENTRY_SIZE * (sc_elems || 1);
writer->objects_table_alloc = OBJECTS_TABLE_ENTRY_SIZE * MAX(sc_elems, 1);
writer->root.objects_table = mem_sys_allocate(writer->objects_table_alloc);
writer->stables_data_alloc = DEFAULT_STABLE_DATA_SIZE;
writer->root.stables_data = mem_sys_allocate(writer->stables_data_alloc);
writer->objects_data_alloc = OBJECT_SIZE_GUESS * (sc_elems || 1);
writer->objects_data_alloc = OBJECT_SIZE_GUESS * MAX(sc_elems, 1);
writer->root.objects_data = mem_sys_allocate(writer->objects_data_alloc);
writer->closures_table_alloc = CLOSURES_TABLE_ENTRY_SIZE * CLOSURES_TABLE_ENTRIES_GUESS;
writer->root.closures_table = mem_sys_allocate(writer->closures_table_alloc);
Expand Down

0 comments on commit bf0a0d8

Please sign in to comment.