Changeset 8453


Ignore:
Timestamp:
03/02/13 15:22:23 (9 years ago)
Author:
gf
Message:

webif: Align fields in templates data before compression.

This prevents crashes on architectures that do not allow unaligned access.
We lose a litlle bit of binary size (~520 bytes) but this is unavoidable
because unaligned access causes crashes.

This fixes crash on DD-WRT reported by basta2k.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/webif/pages_gen.c

    r8446 r8453  
    343343    // Calculate positions at which the values would be storred
    344344    uint32_t cur_pos = 0;
     345    #define align_up(val, align) (val += (align - val % align))
    345346    for (i = 0; i < templates.num; i++) {
    346347        struct template *t = &templates.data[i];
     
    348349        t->data_len = t->buf_len;
    349350        // +1 to leave space for \0
    350         t->ident_ofs = cur_pos; cur_pos += strlen(t->ident) + 1;
    351         t->data_ofs  = cur_pos; cur_pos += t->data_len      + 1;
    352         t->deps_ofs  = cur_pos; cur_pos += strlen(t->deps)  + 1;
     351        t->ident_ofs = cur_pos; cur_pos += strlen(t->ident) + 1; align_up(cur_pos, sizeof(void *));
     352        t->data_ofs  = cur_pos; cur_pos += t->data_len      + 1; align_up(cur_pos, sizeof(void *));
     353        t->deps_ofs  = cur_pos; cur_pos += strlen(t->deps)  + 1; align_up(cur_pos, sizeof(void *));
    353354    }
    354355
Note: See TracChangeset for help on using the changeset viewer.