~ubuntu-branches/ubuntu/trusty/glbsp/trusty

« back to all changes in this revision

Viewing changes to debian/patches/03_wad_level_lumps.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Darren Salt
  • Date: 2006-08-13 12:38:26 UTC
  • Revision ID: james.westby@ubuntu.com-20060813123826-77fvc7gmfrdpscvu
Tags: 2.20-4
* Uploaded to Debian (closes: #368221)
* Bumped standards version to 3.7.2 (no other changes).
* Converted to dpatch.
* Added a patch to fix assumption about map data lump order, allowing
  correct processing of an example WAD supplied by Jon Dowland.
* Added a patch to get rid of sprintf(), vsprintf(), strcpy() and strcat(),
  preferring the likes of asprintf(), where there is the possibility of
  buffer overflow.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## 03_wad_level_lumps.dpatch by Darren Salt <linux@youmustbejoking.demon.co.uk>
 
3
##
 
4
## All lines beginning with `## DP:' are a description of the patch.
 
5
## DP: Don't assume a particular order for map data lumps.
 
6
## DP: (Fixes handling of a wad provided by Jon Dowland.)
 
7
 
 
8
@DPATCH@
 
9
--- glbsp-2.20.orig/wad.c
 
10
+++ glbsp-2.20/wad.c
 
11
@@ -341,16 +341,33 @@
 
12
 static void DetermineLevelNames(void)
 
13
 {
 
14
   lump_t *L, *N;
 
15
-  int i;
 
16
+  int i, j, matched;
 
17
 
 
18
   for (L=wad.dir_head; L; L=L->next)
 
19
   {
 
20
+    // check that the current lump's name doesn't match any level lump name.
 
21
+    //
 
22
+    for (j=0; j<NUM_LEVEL_LUMPS; ++j)
 
23
+      if (strcmp(L->name, level_lumps[j]) == 0)
 
24
+        break;
 
25
+    if (j < NUM_LEVEL_LUMPS)
 
26
+      continue;
 
27
+
 
28
     // check if the next four lumps after the current lump match the
 
29
-    // level-lump names.
 
30
+    // level-lump names (order doesn't matter, but repeated names do)
 
31
     //
 
32
+    matched = 0;
 
33
     for (i=0, N=L->next; (i < 4) && N; i++, N=N->next)
 
34
-      if (strcmp(N->name, level_lumps[i]) != 0)
 
35
+    {
 
36
+      for (j=0; j<NUM_LEVEL_LUMPS; ++j)
 
37
+        if ((~matched & 1<<j) && strcmp(N->name, level_lumps[j]) == 0)
 
38
+        {
 
39
+          matched |= 1<<j;
 
40
+          break;
 
41
+        }
 
42
+      if (j == NUM_LEVEL_LUMPS)
 
43
         break;
 
44
+    }
 
45
 
 
46
     if (i != 4)
 
47
       continue;