~ubuntu-branches/ubuntu/wily/clamav/wily-proposed

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/include/llvm/ADT/ScopedHashTable.h

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Sebastian Andrzej Siewior, Andreas Cadhalpun, Scott Kitterman, Javier Fernández-Sanguino
  • Date: 2015-01-28 00:25:13 UTC
  • mfrom: (0.48.14 sid)
  • Revision ID: package-import@ubuntu.com-20150128002513-lil2oi74cooy4lzr
Tags: 0.98.6+dfsg-1
[ Sebastian Andrzej Siewior ]
* update "fix-ssize_t-size_t-off_t-printf-modifier", include of misc.h was
  missing but was pulled in via the systemd patch.
* Don't leak return codes from libmspack to clamav API. (Closes: #774686).

[ Andreas Cadhalpun ]
* Add patch to avoid emitting incremental progress messages when not
  outputting to a terminal. (Closes: #767350)
* Update lintian-overrides for unused-file-paragraph-in-dep5-copyright.
* clamav-base.postinst: always chown /var/log/clamav and /var/lib/clamav
  to clamav:clamav, not only on fresh installations. (Closes: #775400)
* Adapt the clamav-daemon and clamav-freshclam logrotate scripts,
  so that they correctly work under systemd.
* Move the PidFile variable from the clamd/freshclam configuration files
  to the init scripts. This makes the init scripts more robust against
  misconfiguration and avoids error messages with systemd. (Closes: #767353)
* debian/copyright: drop files from Files-Excluded only present in github
  tarballs
* Drop Workaround-a-bug-in-libc-on-Hurd.patch, because hurd got fixed.
  (see #752237)
* debian/rules: Remove useless --with-system-tommath --without-included-ltdl
  configure options.

[ Scott Kitterman ]
* Stop stripping llvm when repacking the tarball as the system llvm on some
  releases is too old to use
* New upstream bugfix release
  - Library shared object revisions.
  - Includes a patch from Sebastian Andrzej Siewior making ClamAV pid files
    compatible with systemd.
  - Fix a heap out of bounds condition with crafted Yoda's crypter files.
    This issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted mew packer files. This
    issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted upx packer files. This
    issue was discovered by Kevin Szkudlapski of Quarkslab.
  - Fix a heap out of bounds condition with crafted upack packer files. This
    issue was discovered by Sebastian Andrzej Siewior. CVE-2014-9328.
  - Compensate a crash due to incorrect compiler optimization when handling
    crafted petite packer files. This issue was discovered by Sebastian
    Andrzej Siewior.
* Update lintian override for embedded zlib to match new so version

[ Javier Fernández-Sanguino ]
* Updated Spanish Debconf template translation (Closes: #773563)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===- ScopedHashTable.h - A simple scoped hash table ---------------------===//
 
2
//
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is distributed under the University of Illinois Open Source
 
6
// License. See LICENSE.TXT for details.
 
7
//
 
8
//===----------------------------------------------------------------------===//
 
9
//
 
10
// This file implements an efficient scoped hash table, which is useful for
 
11
// things like dominator-based optimizations.  This allows clients to do things
 
12
// like this:
 
13
//
 
14
//  ScopedHashTable<int, int> HT;
 
15
//  {
 
16
//    ScopedHashTableScope<int, int> Scope1(HT);
 
17
//    HT.insert(0, 0);
 
18
//    HT.insert(1, 1);
 
19
//    {
 
20
//      ScopedHashTableScope<int, int> Scope2(HT);
 
21
//      HT.insert(0, 42);
 
22
//    }
 
23
//  }
 
24
//
 
25
// Looking up the value for "0" in the Scope2 block will return 42.  Looking
 
26
// up the value for 0 before 42 is inserted or after Scope2 is popped will
 
27
// return 0.
 
28
//
 
29
//===----------------------------------------------------------------------===//
 
30
 
 
31
#ifndef LLVM_ADT_SCOPEDHASHTABLE_H
 
32
#define LLVM_ADT_SCOPEDHASHTABLE_H
 
33
 
 
34
#include <cassert>
 
35
#include "llvm/ADT/DenseMap.h"
 
36
 
 
37
namespace llvm {
 
38
 
 
39
template <typename K, typename V, typename KInfo = DenseMapInfo<K> >
 
40
class ScopedHashTable;
 
41
 
 
42
template <typename K, typename V, typename KInfo = DenseMapInfo<K> >
 
43
class ScopedHashTableVal {
 
44
  ScopedHashTableVal *NextInScope;
 
45
  ScopedHashTableVal *NextForKey;
 
46
  K Key;
 
47
  V Val;
 
48
public:
 
49
  ScopedHashTableVal(ScopedHashTableVal *nextInScope,
 
50
                     ScopedHashTableVal *nextForKey, const K &key, const V &val)
 
51
    : NextInScope(nextInScope), NextForKey(nextForKey), Key(key), Val(val) {
 
52
  }
 
53
 
 
54
  const K &getKey() const { return Key; }
 
55
  const V &getValue() const { return Val; }
 
56
  V &getValue() { return Val; }
 
57
 
 
58
  ScopedHashTableVal *getNextForKey() { return NextForKey; }
 
59
  const ScopedHashTableVal *getNextForKey() const { return NextForKey; }
 
60
public:
 
61
  ScopedHashTableVal *getNextInScope() { return NextInScope; }
 
62
};
 
63
 
 
64
template <typename K, typename V, typename KInfo = DenseMapInfo<K> >
 
65
class ScopedHashTableScope {
 
66
  /// HT - The hashtable that we are active for.
 
67
  ScopedHashTable<K, V, KInfo> &HT;
 
68
 
 
69
  /// PrevScope - This is the scope that we are shadowing in HT.
 
70
  ScopedHashTableScope *PrevScope;
 
71
 
 
72
  /// LastValInScope - This is the last value that was inserted for this scope
 
73
  /// or null if none have been inserted yet.
 
74
  ScopedHashTableVal<K, V, KInfo> *LastValInScope;
 
75
  void operator=(ScopedHashTableScope&);       // DO NOT IMPLEMENT
 
76
  ScopedHashTableScope(ScopedHashTableScope&); // DO NOT IMPLEMENT
 
77
public:
 
78
  ScopedHashTableScope(ScopedHashTable<K, V, KInfo> &HT);
 
79
  ~ScopedHashTableScope();
 
80
 
 
81
private:
 
82
  friend class ScopedHashTable<K, V, KInfo>;
 
83
  ScopedHashTableVal<K, V, KInfo> *getLastValInScope() {
 
84
    return LastValInScope;
 
85
  }
 
86
  void setLastValInScope(ScopedHashTableVal<K, V, KInfo> *Val) {
 
87
    LastValInScope = Val;
 
88
  }
 
89
};
 
90
 
 
91
 
 
92
template <typename K, typename V, typename KInfo = DenseMapInfo<K> >
 
93
class ScopedHashTableIterator {
 
94
  ScopedHashTableVal<K, V, KInfo> *Node;
 
95
public:
 
96
  ScopedHashTableIterator(ScopedHashTableVal<K, V, KInfo> *node) : Node(node) {}
 
97
 
 
98
  V &operator*() const {
 
99
    assert(Node && "Dereference end()");
 
100
    return Node->getValue();
 
101
  }
 
102
  V *operator->() const {
 
103
    return &Node->getValue();
 
104
  }
 
105
 
 
106
  bool operator==(const ScopedHashTableIterator &RHS) const {
 
107
    return Node == RHS.Node;
 
108
  }
 
109
  bool operator!=(const ScopedHashTableIterator &RHS) const {
 
110
    return Node != RHS.Node;
 
111
  }
 
112
 
 
113
  inline ScopedHashTableIterator& operator++() {          // Preincrement
 
114
    assert(Node && "incrementing past end()");
 
115
    Node = Node->getNextForKey();
 
116
    return *this;
 
117
  }
 
118
  ScopedHashTableIterator operator++(int) {        // Postincrement
 
119
    ScopedHashTableIterator tmp = *this; ++*this; return tmp;
 
120
  }
 
121
};
 
122
 
 
123
 
 
124
template <typename K, typename V, typename KInfo>
 
125
class ScopedHashTable {
 
126
  DenseMap<K, ScopedHashTableVal<K, V, KInfo>*, KInfo> TopLevelMap;
 
127
  ScopedHashTableScope<K, V, KInfo> *CurScope;
 
128
  ScopedHashTable(const ScopedHashTable&); // NOT YET IMPLEMENTED
 
129
  void operator=(const ScopedHashTable&);  // NOT YET IMPLEMENTED
 
130
  friend class ScopedHashTableScope<K, V, KInfo>;
 
131
public:
 
132
  ScopedHashTable() : CurScope(0) {}
 
133
  ~ScopedHashTable() {
 
134
    assert(CurScope == 0 && TopLevelMap.empty() && "Scope imbalance!");
 
135
  }
 
136
 
 
137
  bool count(const K &Key) const {
 
138
    return TopLevelMap.count(Key);
 
139
  }
 
140
 
 
141
  V lookup(const K &Key) {
 
142
    typename DenseMap<K, ScopedHashTableVal<K, V, KInfo>*, KInfo>::iterator
 
143
      I = TopLevelMap.find(Key);
 
144
    if (I != TopLevelMap.end())
 
145
      return I->second->getValue();
 
146
      
 
147
    return V();
 
148
  }
 
149
 
 
150
  void insert(const K &Key, const V &Val) {
 
151
    assert(CurScope && "No scope active!");
 
152
 
 
153
    ScopedHashTableVal<K, V, KInfo> *&KeyEntry = TopLevelMap[Key];
 
154
 
 
155
    KeyEntry= new ScopedHashTableVal<K, V, KInfo>(CurScope->getLastValInScope(),
 
156
                                                  KeyEntry, Key, Val);
 
157
    CurScope->setLastValInScope(KeyEntry);
 
158
  }
 
159
 
 
160
  typedef ScopedHashTableIterator<K, V, KInfo> iterator;
 
161
 
 
162
  iterator end() { return iterator(0); }
 
163
 
 
164
  iterator begin(const K &Key) {
 
165
    typename DenseMap<K, ScopedHashTableVal<K, V, KInfo>*, KInfo>::iterator I =
 
166
      TopLevelMap.find(Key);
 
167
    if (I == TopLevelMap.end()) return end();
 
168
    return iterator(I->second);
 
169
  }
 
170
};
 
171
 
 
172
/// ScopedHashTableScope ctor - Install this as the current scope for the hash
 
173
/// table.
 
174
template <typename K, typename V, typename KInfo>
 
175
ScopedHashTableScope<K, V, KInfo>::
 
176
  ScopedHashTableScope(ScopedHashTable<K, V, KInfo> &ht) : HT(ht) {
 
177
  PrevScope = HT.CurScope;
 
178
  HT.CurScope = this;
 
179
  LastValInScope = 0;
 
180
}
 
181
 
 
182
template <typename K, typename V, typename KInfo>
 
183
ScopedHashTableScope<K, V, KInfo>::~ScopedHashTableScope() {
 
184
  assert(HT.CurScope == this && "Scope imbalance!");
 
185
  HT.CurScope = PrevScope;
 
186
 
 
187
  // Pop and delete all values corresponding to this scope.
 
188
  while (ScopedHashTableVal<K, V, KInfo> *ThisEntry = LastValInScope) {
 
189
    // Pop this value out of the TopLevelMap.
 
190
    if (ThisEntry->getNextForKey() == 0) {
 
191
      assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry &&
 
192
             "Scope imbalance!");
 
193
      HT.TopLevelMap.erase(ThisEntry->getKey());
 
194
    } else {
 
195
      ScopedHashTableVal<K, V, KInfo> *&KeyEntry =
 
196
        HT.TopLevelMap[ThisEntry->getKey()];
 
197
      assert(KeyEntry == ThisEntry && "Scope imbalance!");
 
198
      KeyEntry = ThisEntry->getNextForKey();
 
199
    }
 
200
 
 
201
    // Pop this value out of the scope.
 
202
    LastValInScope = ThisEntry->getNextInScope();
 
203
 
 
204
    // Delete this entry.
 
205
    delete ThisEntry;
 
206
  }
 
207
}
 
208
 
 
209
} // end namespace llvm
 
210
 
 
211
#endif