File: check_memory.patch

package info (click to toggle)
mapsembler2 2.2.4%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,344 kB
  • sloc: cpp: 51,204; ansic: 13,165; sh: 542; makefile: 396; asm: 271; python: 28
file content (45 lines) | stat: -rw-r--r-- 1,426 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Description: check memory of OAHash construction
 This has been written to try debugging why autopkgtest failures occurred on
 32bit architectures.  While the package ended up being removed out of 32 bits
 architectures repositories, this sort of control may remain useful to users of
 mapsembler2 to diagnose issues; this is more useful message than "Segmentation
 fault".
Author: Étienne Mollier
Forwarded: no
Last-Update: 2020-10-15
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- mapsembler2.orig/minia/OAHash.cpp
+++ mapsembler2/minia/OAHash.cpp
@@ -1,6 +1,7 @@
 // open-addressing hash table with linear probing, follows wikipedia
 // to reduce memory, elements with [value == 0] are UNOCCUPIED, deal with it.
 
+#include <errno.h>
 #include <iostream>
 #include <stdio.h>
 #include <string.h>
@@ -13,6 +14,7 @@
 
 OAHash::OAHash(uint64_t max_memory) // in bytes
 {
+    int errcode = 0;
     hash_size = max_memory / sizeof(element_pair);
     if (hash_size == 0)
     {
@@ -21,6 +23,15 @@
     }
     nb_inserted_keys = 0;
     data = (element_pair *) calloc( hash_size, sizeof(element_pair));  //create hashtable
+    if (data == NULL)
+    {
+        errcode = errno;
+        fprintf(stderr, "OAHash: allocation of %lu bytes ",
+                hash_size * sizeof(element_pair));
+        errno = errcode;
+        perror("failed");
+        exit(errcode);
+    }
 }
 
 OAHash::~OAHash()