~ubuntu-branches/ubuntu/lucid/nsis/lucid

« back to all changes in this revision

Viewing changes to Source/crc32.c

  • Committer: Bazaar Package Importer
  • Author(s): Paul Wise
  • Date: 2008-09-01 07:20:44 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080901072044-mjev9xfej6i2d63t
Tags: 2.37-3
Add nsDialogs stack corruption fix from nsis 2.38

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "Platform.h"
2
 
#include "crc32.h"
3
 
#include "exehead/config.h"
4
 
#ifdef NSIS_CONFIG_CRC_SUPPORT
5
 
 
6
 
// this is based on the (slow,small) CRC32 implementation from zlib.
7
 
crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, unsigned int len)
8
 
{
9
 
    static crc32_t crc_table[256];
10
 
 
11
 
    if (!crc_table[1])
12
 
    {
13
 
      crc32_t c;
14
 
      int n, k;
15
 
 
16
 
      for (n = 0; n < 256; n++)
17
 
      {
18
 
        c = (crc32_t)n;
19
 
        for (k = 0; k < 8; k++) c = (c >> 1) ^ (c & 1 ? 0xedb88320L : 0);
20
 
        crc_table[n] = c;
21
 
      }
22
 
    }
23
 
 
24
 
    crc = crc ^ 0xffffffffL;
25
 
    while (len-- > 0) {
26
 
      crc = crc_table[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
27
 
    }
28
 
    return crc ^ 0xffffffffL;
29
 
}
30
 
 
31
 
#endif
 
1
/*
 
2
 * crc32.c
 
3
 * 
 
4
 * This file is a part of NSIS.
 
5
 * 
 
6
 * Copyright (C) 1999-2008 Nullsoft and Contributors
 
7
 * 
 
8
 * Licensed under the zlib/libpng license (the "License");
 
9
 * you may not use this file except in compliance with the License.
 
10
 * 
 
11
 * Licence details can be found in the file COPYING.
 
12
 * 
 
13
 * This software is provided 'as-is', without any express or implied
 
14
 * warranty.
 
15
 */
 
16
 
 
17
#include "Platform.h"
 
18
#include "crc32.h"
 
19
#include "exehead/config.h"
 
20
#ifdef NSIS_CONFIG_CRC_SUPPORT
 
21
 
 
22
// this is based on the (slow,small) CRC32 implementation from zlib.
 
23
crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, unsigned int len)
 
24
{
 
25
    static crc32_t crc_table[256];
 
26
 
 
27
    if (!crc_table[1])
 
28
    {
 
29
      crc32_t c;
 
30
      int n, k;
 
31
 
 
32
      for (n = 0; n < 256; n++)
 
33
      {
 
34
        c = (crc32_t)n;
 
35
        for (k = 0; k < 8; k++) c = (c >> 1) ^ (c & 1 ? 0xedb88320L : 0);
 
36
        crc_table[n] = c;
 
37
      }
 
38
    }
 
39
 
 
40
    crc = crc ^ 0xffffffffL;
 
41
    while (len-- > 0) {
 
42
      crc = crc_table[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
 
43
    }
 
44
    return crc ^ 0xffffffffL;
 
45
}
 
46
 
 
47
#endif