File: 16-fix-compilation-warnings.patch

package info (click to toggle)
dmalloc 5.5.2-14
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 5,500 kB
  • sloc: ansic: 13,014; makefile: 456; sh: 219; perl: 175; cpp: 36
file content (460 lines) | stat: -rw-r--r-- 16,813 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
From: Carlos Maddela <e7appew@gmail.com>
Date: Fri, 16 Dec 2016 01:50:58 +1100
Subject: Fix compilation warnings.

Description: Fix compilation warnings.
Author: Carlos Maddela <e7appew@gmail.com>
Forwarded: no
Last-Update: 2016-12-16
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
---
 chunk.c     |  8 +++---
 dmalloc.c   |  2 +-
 dmalloc_t.c | 84 ++++++++++++++++++++++++++++++-------------------------------
 error.c     | 23 ++++++++++-------
 heap.c      |  3 ++-
 malloc.c    | 17 +++++++------
 6 files changed, 73 insertions(+), 64 deletions(-)

diff --git a/chunk.c b/chunk.c
index acdf449..3ecea5b 100644
--- a/chunk.c
+++ b/chunk.c
@@ -27,6 +27,7 @@
  */
 
 #include <ctype.h>
+#include <stdint.h>
 
 #if HAVE_STRING_H
 # include <string.h>
@@ -792,7 +793,7 @@ static unsigned int get_align_overhead(unsigned int align,int fence_b)
 /*just tests if the remainder is zero*/
 static int is_aligned_to(char * p, unsigned int alignment)
 {
-	return 0==(((unsigned int)p)%alignment);//alignment must not be zero
+	return 0==(((uintptr_t)p)%alignment);//alignment must not be zero
 }
 
 /*advance the pointer bytewise until it is aligned. returns result*/
@@ -1671,7 +1672,7 @@ static	int	check_used_slot(const skip_alloc_t *slot_p,
 				const int strlen_b, const int min_size)
 {
   const char	*file, *name_p, *bounds_p, *mem_p;
-  unsigned int	line, num;
+  unsigned int	line;
   pnt_info_t	pnt_info;
   
   if (! (BIT_IS_SET(slot_p->sa_flags, ALLOC_FLAG_USER)
@@ -1716,7 +1717,7 @@ static	int	check_used_slot(const skip_alloc_t *slot_p,
   */
 
   if (pnt_info.pi_fence_b) {
-    if((pnt_info.pi_fence_top+FENCE_TOP_SIZE)>pnt_info.pi_alloc_bounds) {
+    if((void *)((char *)pnt_info.pi_fence_top+FENCE_TOP_SIZE)>pnt_info.pi_alloc_bounds) {
       dmalloc_errno = ERROR_SLOT_CORRUPT;
       return 0;
     }
@@ -3297,7 +3298,6 @@ unsigned long	_dmalloc_chunk_count_changed(const unsigned long mark,
       mem_count += slot_p->sa_user_size;
     }
     else if (count_freed_b && freed_b) {
-      char * a,*b;
       mem_count += slot_p->sa_user_size;
     }
   }
diff --git a/dmalloc.c b/dmalloc.c
index 8f69381..b6016f3 100644
--- a/dmalloc.c
+++ b/dmalloc.c
@@ -700,7 +700,7 @@ static	void	dump_current(void)
   const char	*env_str;
   DMALLOC_PNT	addr;
   unsigned long	inter, limit_val, loc_start_size, loc_start_iter;
-  long		addr_count;
+  unsigned long	addr_count;
   int		lock_on, loc_start_line;
   unsigned int	flags;
   
diff --git a/dmalloc_t.c b/dmalloc_t.c
index 74d5ec2..cd40eee 100644
--- a/dmalloc_t.c
+++ b/dmalloc_t.c
@@ -183,8 +183,8 @@ static	void	free_slot(const int iter_c, pnt_info_t *slot_p,
   pnt_info_t	*this_p, *prev_p;
   
   if (verbose_b) {
-    (void)printf("%d: free'd %d bytes from slot %d (%#lx)\n",
-		 iter_c + 1, slot_p->pi_size, slot_p - pointer_grid,
+    (void)printf("%d: free'd %d bytes from slot %ld (%#lx)\n",
+		 iter_c + 1, slot_p->pi_size, (long) (slot_p - pointer_grid),
 		 (long)slot_p->pi_pnt);
   }
   
@@ -291,8 +291,8 @@ static	int	do_random(const int iter_n)
       free_c++;
       
       if (verbose_b) {
-	(void)printf("%d: free'd %d bytes from slot %d (%#lx)\n",
-		     iter_c + 1, pnt_p->pi_size, pnt_p - pointer_grid,
+	(void)printf("%d: free'd %d bytes from slot %ld (%#lx)\n",
+		     iter_c + 1, pnt_p->pi_size, (long) (pnt_p - pointer_grid),
 		     (long)pnt_p->pi_pnt);
       }
       
@@ -326,8 +326,8 @@ static	int	do_random(const int iter_n)
       pnt_p->pi_pnt = malloc(amount);
       
       if (verbose_b) {
-	(void)printf("%d: malloc %d of max %d into slot %d.  got %#lx\n",
-		     iter_c + 1, amount, max_avail, pnt_p - pointer_grid,
+	(void)printf("%d: malloc %d of max %d into slot %ld.  got %#lx\n",
+		     iter_c + 1, amount, max_avail, (long) (pnt_p - pointer_grid),
 		     (long)pnt_p->pi_pnt);
       }
       break;
@@ -338,8 +338,8 @@ static	int	do_random(const int iter_n)
       pnt_p->pi_pnt = calloc(amount, sizeof(char));
       
       if (verbose_b) {
-	(void)printf("%d: calloc %d of max %d into slot %d.  got %#lx\n",
-		     iter_c + 1, amount, max_avail, pnt_p - pointer_grid,
+	(void)printf("%d: calloc %d of max %d into slot %ld.  got %#lx\n",
+		     iter_c + 1, amount, max_avail, (long) (pnt_p - pointer_grid),
 		     (long)pnt_p->pi_pnt);
       }
       
@@ -378,9 +378,9 @@ static	int	do_random(const int iter_n)
       max_avail += pnt_p->pi_size;
       
       if (verbose_b) {
-	(void)printf("%d: realloc %d from %d of max %d slot %d.  got %#lx\n",
+	(void)printf("%d: realloc %d from %d of max %d slot %ld.  got %#lx\n",
 		     iter_c + 1, amount, pnt_p->pi_size, max_avail,
-		     pnt_p - pointer_grid, (long)pnt_p->pi_pnt);
+		     (long) (pnt_p - pointer_grid), (long)pnt_p->pi_pnt);
       }
       
       if (amount == 0) {
@@ -410,9 +410,9 @@ static	int	do_random(const int iter_n)
       max_avail += pnt_p->pi_size;
       
       if (verbose_b) {
-	(void)printf("%d: recalloc %d from %d of max %d slot %d.  got %#lx\n",
+	(void)printf("%d: recalloc %d from %d of max %d slot %ld.  got %#lx\n",
 		     iter_c + 1, amount, pnt_p->pi_size, max_avail,
-		     pnt_p - pointer_grid, (long)pnt_p->pi_pnt);
+		     (long) (pnt_p - pointer_grid), (long)pnt_p->pi_pnt);
       }
       
       /* test the returned block to make sure that is has been cleared */
@@ -444,8 +444,8 @@ static	int	do_random(const int iter_n)
       pnt_p->pi_pnt = valloc(amount);
       
       if (verbose_b) {
-	(void)printf("%d: valloc %d of max %d into slot %d.  got %#lx\n",
-		     iter_c + 1, amount, max_avail, pnt_p - pointer_grid,
+	(void)printf("%d: valloc %d of max %d into slot %ld.  got %#lx\n",
+		     iter_c + 1, amount, max_avail, (long) (pnt_p - pointer_grid),
 		     (long)pnt_p->pi_pnt);
       }
       break;
@@ -2790,13 +2790,13 @@ static	int	check_special(void)
     dmalloc_errno = ERROR_NONE;
     ret = strndup(pnt, size);
     
-    if (dmalloc_errno != ERROR_NONE) {
+    if (ret == NULL || dmalloc_errno != ERROR_NONE) {
       if (! silent_b) {
 	(void)printf("   ERROR: strndup shouldn't produce error: %s (err %d)\n",
 		     dmalloc_strerror(dmalloc_errno), dmalloc_errno);
       }
       final = 0;
-    } else if (strcmp(pnt, str) != 0) {
+    } else if (strcmp(pnt, ret) != 0) {
       if (! silent_b) {
 	(void)printf("   ERROR: strndup should have copied string\n");
       }
@@ -2806,13 +2806,13 @@ static	int	check_special(void)
     dmalloc_errno = ERROR_NONE;
     ret = strndup(pnt, size + 1);
     
-    if (dmalloc_errno != ERROR_NONE) {
+    if (ret == NULL || dmalloc_errno != ERROR_NONE) {
       if (! silent_b) {
 	(void)printf("   ERROR: strndup shouldn't produce error: %s (err %d)\n",
 		     dmalloc_strerror(dmalloc_errno), dmalloc_errno);
       }
       final = 0;
-    } else if (strcmp(pnt, str) != 0) {
+    } else if (strcmp(pnt, ret) != 0) {
       if (! silent_b) {
 	(void)printf("   ERROR: strndup should have copied string\n");
       }
@@ -3277,8 +3277,8 @@ static	int	check_special(void)
     
     else if (user_size != (SIZE_ARG) * (COUNT_ARG)) {
       if (! silent_b) {
-	(void)printf("   ERROR: calloc size should be %d but was %d.\n",
-		     (SIZE_ARG) * (COUNT_ARG), user_size);
+	(void)printf("   ERROR: calloc size should be %d but was %lu.\n",
+		     (SIZE_ARG) * (COUNT_ARG), (unsigned long) user_size);
       }
       final = 0;
     }
@@ -3926,47 +3926,47 @@ static	void	track_alloc_trxn(const char *file, const unsigned int line,
   
   switch (func_id) {
   case DMALLOC_FUNC_MALLOC:
-    (void)printf("%s malloc %d bytes got %#lx\n",
-		 file_line, byte_size, (long)new_addr);
+    (void)printf("%s malloc %lu bytes got %#lx\n",
+		 file_line, (unsigned long) byte_size, (long)new_addr);
     break;
   case DMALLOC_FUNC_CALLOC:
-    (void)printf("%s calloc %d bytes got %#lx\n",
-		 file_line, byte_size, (long)new_addr);
+    (void)printf("%s calloc %lu bytes got %#lx\n",
+		 file_line, (unsigned long) byte_size, (long)new_addr);
     break;
   case DMALLOC_FUNC_REALLOC:
-    (void)printf("%s realloc %d bytes from %#lx got %#lx\n",
-		 file_line, byte_size, (long)old_addr, (long)new_addr);
+    (void)printf("%s realloc %lu bytes from %#lx got %#lx\n",
+		 file_line, (unsigned long) byte_size, (long)old_addr, (long)new_addr);
     break;
   case DMALLOC_FUNC_RECALLOC:
-    (void)printf("%s recalloc %d bytes from %#lx got %#lx\n",
-		 file_line, byte_size, (long)old_addr, (long)new_addr);
+    (void)printf("%s recalloc %lu bytes from %#lx got %#lx\n",
+		 file_line, (unsigned long) byte_size, (long)old_addr, (long)new_addr);
     break;
   case DMALLOC_FUNC_MEMALIGN:
-    (void)printf("%s memalign %d bytes alignment %d got %#lx\n",
-		 file_line, byte_size, alignment, (long)new_addr);
+    (void)printf("%s memalign %lu bytes alignment %lu got %#lx\n",
+		 file_line, (unsigned long) byte_size, (unsigned long) alignment, (long)new_addr);
     break;
   case DMALLOC_FUNC_POSIX_MEMALIGN:
-    (void)printf("%s posix_memalign %d bytes alignment %d got %#lx\n",
-		 file_line, byte_size, alignment, (long)new_addr);
+    (void)printf("%s posix_memalign %lu bytes alignment %lu got %#lx\n",
+		 file_line, (unsigned long) byte_size, (unsigned long) alignment, (long)new_addr);
     break;
   case DMALLOC_FUNC_VALLOC:
-    (void)printf("%s valloc %d bytes alignment %d got %#lx\n",
-		 file_line, byte_size, alignment, (long)new_addr);
+    (void)printf("%s valloc %lu bytes alignment %lu got %#lx\n",
+		 file_line, (unsigned long) byte_size, (unsigned long) alignment, (long)new_addr);
     break;
   case DMALLOC_FUNC_STRDUP:
-    (void)printf("%s strdup %d bytes ot %#lx\n",
-		 file_line, byte_size, (long)new_addr);
+    (void)printf("%s strdup %lu bytes ot %#lx\n",
+		 file_line, (unsigned long) byte_size, (long)new_addr);
     break;
   case DMALLOC_FUNC_FREE:
     (void)printf("%s free %#lx\n", file_line, (long)old_addr);
     break;
   case DMALLOC_FUNC_NEW:
-    (void)printf("%s new %d bytes got %#lx\n",
-		 file_line, byte_size, (long)new_addr);
+    (void)printf("%s new %lu bytes got %#lx\n",
+		 file_line, (unsigned long) byte_size, (long)new_addr);
     break;
   case DMALLOC_FUNC_NEW_ARRAY:
-    (void)printf("%s new[] %d bytes got %#lx\n",
-		 file_line, byte_size, (long)new_addr);
+    (void)printf("%s new[] %lu bytes got %#lx\n",
+		 file_line, (unsigned long) byte_size, (long)new_addr);
     break;
   case DMALLOC_FUNC_DELETE:
     (void)printf("%s delete %#lx\n", file_line, (long)old_addr);
@@ -3975,9 +3975,9 @@ static	void	track_alloc_trxn(const char *file, const unsigned int line,
     (void)printf("%s delete[] %#lx\n", file_line, (long)old_addr);
     break;
   default:
-    (void)printf("%s unknown function %d bytes, %d alignment, %#lx old-addr "
+    (void)printf("%s unknown function %lu bytes, %lu alignment, %#lx old-addr "
 		 "%#lx new-addr\n",
-		 file_line, byte_size, alignment, (long)old_addr,
+		 file_line, (unsigned long) byte_size, (unsigned long) alignment, (long)old_addr,
 		 (long)new_addr);
     break;
   }
diff --git a/error.c b/error.c
index bb8c3fe..8657fca 100644
--- a/error.c
+++ b/error.c
@@ -149,7 +149,7 @@ static	char	message_str[1024];		/* message string buffer */
 static	void	build_logfile_path(char *buf, const int buf_len)
 {
   char	*bounds_p;
-  char	*path_p, *buf_p, *start_p;
+  char	*path_p, *buf_p;
   int	len;
   
   if (dmalloc_logpath == NULL) {
@@ -159,8 +159,7 @@ static	void	build_logfile_path(char *buf, const int buf_len)
   
   buf_p = buf;
   bounds_p = buf + buf_len;
-  
-  start_p = dmalloc_logpath;
+
   for (path_p = dmalloc_logpath; *path_p != '\0'; path_p++) {
     
     /* if we don't have to do anything special then just continue */
@@ -235,7 +234,8 @@ static	void	build_logfile_path(char *buf, const int buf_len)
     len = loc_snprintf(error_str, sizeof(error_str),
 		       "debug-malloc library: logfile path too large '%s'\r\n",
 		       dmalloc_logpath);
-    (void)write(STDERR, error_str, len);
+    if (write(STDERR, error_str, len) < 0) {
+    }
   }
   
   *buf_p = '\0';
@@ -277,7 +277,8 @@ void	_dmalloc_open_log(void)
     len = loc_snprintf(error_str, sizeof(error_str),
 		       "debug-malloc library: could not open '%s'\r\n",
 		       log_path);
-    (void)write(STDERR, error_str, len);
+    if (write(STDERR, error_str, len) < 0) {
+    }
     /* disable log_path */
     dmalloc_logpath = NULL;
     return;
@@ -593,12 +594,14 @@ void	_dmalloc_vmessage(const char *format, va_list args)
   
   /* do we need to write the message to the logfile */
   if (dmalloc_logpath != NULL) {
-    (void)write(outfile_fd, message_str, len);
+    if (write(outfile_fd, message_str, len) < 0) {
+    }
   }
   
   /* do we need to print the message? */
   if (BIT_IS_SET(_dmalloc_flags, DEBUG_PRINT_MESSAGES)) {
-    (void)write(STDERR, message_str, len);
+    if (write(STDERR, message_str, len) < 0) {
+    }
   }
 }
 
@@ -634,12 +637,14 @@ void	_dmalloc_die(const int silent_b)
     len = loc_snprintf(error_str, sizeof(error_str),
 		       "debug-malloc library: %s program, fatal error\r\n",
 		       stop_str);
-    (void)write(STDERR, error_str, len);
+    if (write(STDERR, error_str, len) < 0) {
+    }
     if (dmalloc_errno != ERROR_NONE) {
       len = loc_snprintf(error_str, sizeof(error_str),
 			 "   Error: %s (err %d)\r\n",
 			 dmalloc_strerror(dmalloc_errno), dmalloc_errno);
-      (void)write(STDERR, error_str, len);
+      if (write(STDERR, error_str, len) < 0) {
+      }
     }
   }
   
diff --git a/heap.c b/heap.c
index d592a22..2adf43e 100644
--- a/heap.c
+++ b/heap.c
@@ -117,7 +117,8 @@ static	void	*heap_extend(const int incr)
       int	len;
       len = loc_snprintf(str, sizeof(str),
 			 "\r\ndmalloc: critical error: could not extend heap %u more bytes\r\n", incr);
-      (void)write(STDERR, str, len);
+      if (write(STDERR, str, len) < 0) {
+      }
       _dmalloc_die(0);
     }
     dmalloc_errno = ERROR_ALLOC_FAILED;
diff --git a/malloc.c b/malloc.c
index ec20391..034f8eb 100644
--- a/malloc.c
+++ b/malloc.c
@@ -130,7 +130,6 @@ char		*dmalloc_logpath = NULL;
 static	int		enabled_b = 0;		/* have we started yet? */
 static	int		in_alloc_b = 0;		/* can't be here twice */
 static	int		do_shutdown_b = 0;	/* execute shutdown soon */
-static	int		memalign_warn_b = 0;	/* memalign warning printed?*/
 static	dmalloc_track_t	tracking_func = NULL;	/* memory trxn tracking func */
 
 /* debug variables */
@@ -298,7 +297,7 @@ static	void	process_environ(const char *option_str)
   }
   
   _dmalloc_environ_process(options, &_dmalloc_address,
-			   (long *)&_dmalloc_address_seen_n, &_dmalloc_flags,
+			   &_dmalloc_address_seen_n, &_dmalloc_flags,
 			   &_dmalloc_check_interval, &_dmalloc_lock_on,
 			   &dmalloc_logpath, &start_file, &start_line,
 			   &start_iter, &start_size, &_dmalloc_memory_limit);
@@ -770,7 +769,7 @@ DMALLOC_PNT	dmalloc_malloc(const char *file, const int line,
 			       const int xalloc_b)
 {
   void		*new_p;
-  DMALLOC_SIZE	align;
+  DMALLOC_SIZE	align = 0;
   
 #if DMALLOC_SIZE_UNSIGNED == 0
   if (size < 0) {
@@ -819,7 +818,8 @@ DMALLOC_PNT	dmalloc_malloc(const char *file, const int line,
 		       size,
 		       _dmalloc_chunk_desc_pnt(desc, sizeof(desc),
 					       file, line));
-    (void)write(STDERR, mess, strlen(mess));
+    if (write(STDERR, mess, strlen(mess)) < 0) {
+    }
     _exit(1);
   }
   
@@ -991,7 +991,8 @@ DMALLOC_PNT	dmalloc_realloc(const char *file, const int line,
 		       "Out of memory while reallocating %d bytes from '%s'\n",
 		       new_size, _dmalloc_chunk_desc_pnt(desc, sizeof(desc),
 							 file, line));
-    (void)write(STDERR, mess, strlen(mess));
+    if (write(STDERR, mess, strlen(mess)) < 0) {
+    }
     _exit(1);
   }
   
@@ -1422,7 +1423,7 @@ char	*strndup(const char *string, const DMALLOC_SIZE len)
   if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {
     if (! dmalloc_verify_pnt_strsize(file, 0 /* no line */, "strdup", string,
 				     0 /* not exact */, 1 /* strlen */,
-				     size)) {
+				     len)) {
       dmalloc_message("bad pointer argument found in strdup");
     }
   }
@@ -1473,6 +1474,7 @@ DMALLOC_FREE_RET	free(DMALLOC_PNT pnt)
   ret = dmalloc_free(file, DMALLOC_DEFAULT_LINE, pnt, DMALLOC_FUNC_FREE);
   
 #if (defined(__STDC__) && __STDC__ == 1) || defined(__cplusplus) || defined(STDC_HEADERS)
+  (void) ret;
 #else
   return ret;
 #endif
@@ -1504,6 +1506,7 @@ DMALLOC_FREE_RET	cfree(DMALLOC_PNT pnt)
   ret = dmalloc_free(file, DMALLOC_DEFAULT_LINE, pnt, DMALLOC_FUNC_CFREE);
   
 #if (defined(__STDC__) && __STDC__ == 1) || defined(__cplusplus) || defined(STDC_HEADERS)
+  (void) ret;
 #else
   return ret;
 #endif
@@ -1912,7 +1915,7 @@ int	dmalloc_tag_pnt(const DMALLOC_PNT pnt,char *file,int line)
 	}
 	_dmalloc_chunk_tag_pnt(p,file,line);
 	dmalloc_out();
-
+	return 1;
 }