File: 1060-const-string-literals.patch

package info (click to toggle)
nam 1.15-10
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 29,532 kB
  • sloc: cpp: 17,346; tcl: 10,655; sh: 2,997; ansic: 1,253; makefile: 139; perl: 66
file content (446 lines) | stat: -rw-r--r-- 15,176 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
Description: Fix incorrect constness of strings.
 Fixes this warning from the compiler: ISO C++ forbids converting a string constant
 to ‘char*’ [-Wwrite-strings]

 This ensure a strict separation between const and modifiable strings, and
 fix a few bugs avoiding delete with strings on the stack.
Author: Petter Reinholdtsen <pere@debian.org>
Forwarded: no
Last-Update: 2024-10-06
---
Index: nam-salsa/node.h
===================================================================
--- nam-salsa.orig/node.h	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/node.h	2024-10-06 10:19:09.000000000 +0200
@@ -201,11 +201,11 @@
 	inline void mark(int v) { mark_ = v; }
 	inline int mass() const { return mass_; }
 	inline void mass(int m) {mass_=m;}
-	virtual char *style() {return 0;}
+	virtual const char *style() {return 0;}
 	virtual void update(double now);
 
 	void init_color(const char *clr);
-	void set_down(char *color);
+	void set_down(const char *color);
 	void set_up();
 	inline int isdown() const { return (state_ == DOWN); }
 
@@ -277,7 +277,7 @@
 	virtual void size(double s);
 	virtual void draw(View*, double now);
 	virtual void place(double x, double y);
-	char *style() {return "box";}
+	const char *style() {return "box";}
 private:
 	float x0_, y0_;
 	float x1_, y1_;
@@ -288,7 +288,7 @@
 	CircleNode(const char* name, double size);
 	virtual void size(double s);
 	virtual void draw(View*, double now);
-	char *style() {return "circle";}
+	const char *style() {return "circle";}
 private:
 	float radius_;
 };
@@ -299,7 +299,7 @@
 	virtual void size(double s);
 	virtual void draw(View*, double now);
 	virtual void place(double x, double y);
-	char *style() {return "hexagon";}
+	const char *style() {return "hexagon";}
 private:
 	float ypoly_[6];
 	float xpoly_[6];
@@ -315,7 +315,7 @@
 	virtual void delete_packet(Packet *p);
 	virtual double x(Edge *e) const;
 	virtual double y(Edge *e) const;
-	char *style() {return "virtual";}
+	const char *style() {return "virtual";}
 private:
 	Lan *lan_;
 };
Index: nam-salsa/parser.cc
===================================================================
--- nam-salsa.orig/parser.cc	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/parser.cc	2024-10-06 10:24:29.803546098 +0200
@@ -41,8 +41,8 @@
 //----------------------------------------------------------------------
 //
 //----------------------------------------------------------------------
-Attribute::Attribute(char _flag, void * _value_ptr, char * _value_type,
-                     char * _default_value, bool _required, char * _label) {
+Attribute::Attribute(char _flag, void * _value_ptr, const char * _value_type,
+                     const char * _default_value, bool _required, const char * _label) {
   flag = _flag;
   value_ptr = _value_ptr;
   other_ptr = NULL;
@@ -57,8 +57,8 @@
 //----------------------------------------------------------------------
 //
 //----------------------------------------------------------------------
-char * 
-Attribute::parseValue(char * run, char * line) {
+const char * 
+Attribute::parseValue(const char * run, const char * line) {
   char buffer[MAXVALUE];
   double angle;
 
@@ -240,9 +240,9 @@
 //----------------------------------------------------------------------
 //
 //----------------------------------------------------------------------
-TraceSyntax::TraceSyntax(char event_id, char * _label) {
-  type = event_id;
-  label = _label;
+TraceSyntax::TraceSyntax(const char event_id, const char * _label)
+ : type(event_id), label(_label)
+{
   attributes = NULL;
   last_attribute = NULL;
   total_required_attributes = 0;
@@ -255,9 +255,9 @@
 //
 //----------------------------------------------------------------------
 Attribute * 
-TraceSyntax::addAttribute(char flag, void * value_ptr, char * type,
-                          char * default_value, bool required,
-                          char * label) {
+TraceSyntax::addAttribute(char flag, void * value_ptr, const char * type,
+                          const char * default_value, bool required,
+                          const char * label) {
   Attribute * attribute = new Attribute(flag, value_ptr, type,
                                         default_value, required, label);
 
@@ -290,9 +290,9 @@
 //     nam syntax.
 //----------------------------------------------------------------------
 Attribute * 
-TraceSyntax::addAttribute(char flag, void * value_ptr, char * type,
-                          char * default_value, bool required,
-                          char * label, void * other_ptr) {
+TraceSyntax::addAttribute(char flag, void * value_ptr, const char * type,
+                          const char * default_value, bool required,
+                          const char * label, void * other_ptr) {
   Attribute * attribute;
 
   attribute = addAttribute(flag, value_ptr, type, default_value, required, label);
@@ -722,7 +722,7 @@
 bool
 ParseTable::parseLine(char * line) {
   bool success = true;
-  char * run = line; // run down the nam event line
+  const char * run = line; // run down the nam event line
   TraceSyntax * ts = syntax_list;
   Attribute * attribute = NULL;
   char attribute_type;
@@ -837,7 +837,7 @@
 //
 //---------------------------------------------------------------------
 TraceSyntax * 
-ParseTable::addTraceSyntax(char id, char * label) {
+ParseTable::addTraceSyntax(const char id, const char * label) {
   TraceSyntax * ts;
   
   if (!syntax_list) {
@@ -870,8 +870,8 @@
 //---------------------------------------------------------------------
 //
 //---------------------------------------------------------------------
-char *
-eatSpaces(char * marker) {
+const char *
+eatSpaces(const char * marker) {
   while (*marker == ' ' || *marker == '\t') {
     marker++; 
   }
@@ -880,8 +880,8 @@
 //---------------------------------------------------------------------
 //
 //---------------------------------------------------------------------
-char *
-advanceToSpace(char * marker) {
+const char *
+advanceToSpace(const char * marker) {
   while (!isspace(*marker)) {
     marker++; 
   }
@@ -891,7 +891,7 @@
 //---------------------------------------------------------------------
 //
 //---------------------------------------------------------------------
-char * advanceToNextFlag(char * marker) {
+const char * advanceToNextFlag(const char * marker) {
   while (*marker != '-' && *marker != '\n' && *marker != '\0') {
     marker++;
   }
@@ -901,7 +901,7 @@
 //---------------------------------------------------------------------
 //
 //---------------------------------------------------------------------
-char * advanceToEndofLine(char * marker) {
+const char * advanceToEndofLine(const char * marker) {
   while (*marker != '\n' && *marker != '\0') {
     marker++;
   }
@@ -923,9 +923,9 @@
 //
 //     Note: May need to add in \r check for Micro$oft Windows
 //---------------------------------------------------------------------
-char *
-extractString(char * original, char * output) {
-  char * run; // run along the string
+const char *
+extractString(const char * original, char * output) {
+  const char * run; // run along the string
   int count = 0;  // size of the copied string, should be less than MAXNAME
 
   run = original;
Index: nam-salsa/parser.h
===================================================================
--- nam-salsa.orig/parser.h	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/parser.h	2024-10-06 10:22:40.790534753 +0200
@@ -42,24 +42,24 @@
 class Attribute {
 public:
   char flag;
-  char * value_type;
+  const char * value_type;
   void * value_ptr;
   void * other_ptr;  // Used for backwards compatibility hacks
-  char * default_value;
+  const char * default_value;
   bool required;
   bool dual_use;
   bool seen;
-  char * label;
+  const char * label;
   Attribute * next;
 
 public:
   // value_ptr is the location to store a read value in the TraceEvent record
-  Attribute(char _flag, void * _value_ptr, char * _value_type, char * _default_value, 
-            bool _required, char * _label);
+  Attribute(char _flag, void * _value_ptr, const char * _value_type, const char * _default_value, 
+            bool _required, const char * _label);
 
   void dualUse(void * _value_ptr, char * _value_type, char * _label);
 
-  char * parseValue(char * run, char * line);
+  const char * parseValue(const char * run, const char * line);
   void setDefaultValue();
 
 private:
@@ -70,8 +70,8 @@
 
 class TraceSyntax {
 public:
-  char type;
-  char * label;
+  const char type;
+  const char * label;
   Attribute * attributes;
   int total_required_attributes;
   int number_of_attributes;
@@ -81,13 +81,13 @@
   Attribute * last_attribute;
   
 public:
-  TraceSyntax(char event_id, char * _label);
-  Attribute * addAttribute(char flag, void * value_ptr, char * type,
-                           char * default_value, bool required,
-                           char * label);
-  Attribute * addAttribute(char flag, void * value_ptr, char * type,
-                           char * default_value, bool required,
-                           char * label, void * other_ptr);
+  TraceSyntax(const char event_id, const char * _label);
+  Attribute * addAttribute(const char flag, void * value_ptr, const char * type,
+                           const char * default_value, bool required,
+                           const char * label);
+  Attribute * addAttribute(const char flag, void * value_ptr, const char * type,
+                           const char * default_value, bool required,
+                           const char * label, void * other_ptr);
   void setDefaultAttributeValues();
 };
 
@@ -108,13 +108,13 @@
   int print(FILE * stream);
   int printLatex(FILE * stream);
   bool parseLine(char * line);
-  TraceSyntax * addTraceSyntax(char id, char * label);
+  TraceSyntax * addTraceSyntax(const char id, const char * label);
 };
 
-char * eatSpaces(char * marker);
-char * advanceToSpace(char * marker);
-char * advanceToNextFlag(char * marker);
-char * advanceToEndofLine(char * marker);
-char * extractString(char * original, char * output);
+const char * eatSpaces(const char * marker);
+const char * advanceToSpace(const char * marker);
+const char * advanceToNextFlag(const char * marker);
+const char * advanceToEndofLine(const char * marker);
+const char * extractString(const char * original, char * output);
 #endif
 
Index: nam-salsa/lossmodel.cc
===================================================================
--- nam-salsa.orig/lossmodel.cc	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/lossmodel.cc	2024-10-06 10:19:09.000000000 +0200
@@ -117,7 +117,10 @@
   x_ = 0.0;
   y_ = 0.0;
   angle_ = NO_ANGLE;
-  color_ = "black";
+  if (color_) {
+    delete []color_;
+  }
+  color_ = strdup("black");
   paint_ = Paint::instance()->thin();
 
   loss_unit_ = NULL;
Index: nam-salsa/queuehandle.cc
===================================================================
--- nam-salsa.orig/queuehandle.cc	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/queuehandle.cc	2024-10-06 10:19:09.000000000 +0200
@@ -142,7 +142,10 @@
   x_ = 0.0;
   y_ = 0.0;
   angle_ = NO_ANGLE;
-  color_ = "black";
+  if (color_) {
+    delete []color_;
+  }
+  color_ = strdup("black");
   paint_ = Paint::instance()->thin();
   width_ = 10.0;
   height_ = 10.0;
@@ -318,7 +321,7 @@
 void
 QueueHandle::draw(View * view, double time) {
 	double label_width, label_height, label_x, label_y;
-	char * label = "Q";
+	const char * label = "Q";
 
 	if (edge_) {
 
Index: nam-salsa/edge.cc
===================================================================
--- nam-salsa.orig/edge.cc	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/edge.cc	2024-10-06 10:19:09.000000000 +0200
@@ -285,7 +285,7 @@
 	oldPaint_ = paint_;
 }
 
-void Edge::set_down(char *color)
+void Edge::set_down(const char *color)
 {
 	// If current color is down, don't change it again.
 	// Assuming only one down color. User can change this behavior
Index: nam-salsa/edge.h
===================================================================
--- nam-salsa.orig/edge.h	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/edge.h	2024-10-06 10:19:09.000000000 +0200
@@ -120,7 +120,7 @@
 	inline int no_of_packets() const {return no_of_packets_;}
 
 	void init_color(const char *clr);
-	void set_down(char *clr);
+	void set_down(const char *clr);
 	void set_up();
 	inline int isdown() const { return (state_==DOWN); }
 
Index: nam-salsa/node.cc
===================================================================
--- nam-salsa.orig/node.cc	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/node.cc	2024-10-06 10:19:09.000000000 +0200
@@ -451,7 +451,7 @@
   oldPaint_ = paint_;
 }
 
-void Node::set_down(char *color)
+void Node::set_down(const char *color)
 {
 	// If current color is down, don't change it again.
 	// Assuming only one down color. User can change this behavior
Index: nam-salsa/trafficsource.cc
===================================================================
--- nam-salsa.orig/trafficsource.cc	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/trafficsource.cc	2024-10-06 10:19:09.000000000 +0200
@@ -147,7 +147,10 @@
   window_ = 20;
   windowInit_ = 1;
   maxcwnd_ = 0;
-  color_ = "green";
+  if (color_) {
+    delete []color_;
+  }
+  color_ = strdup("green");
   anchor_ = 0;
   paint_ = Paint::instance()->thin();
 
Index: nam-salsa/main.cc
===================================================================
--- nam-salsa.orig/main.cc	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/main.cc	2024-10-06 10:19:09.000000000 +0200
@@ -226,11 +226,10 @@
 	return (TCL_OK);
 }
 
-char* parse_assignment(char* cp)
+const char* parse_assignment(const char* cp)
 {
 	cp = strchr(cp, '=');
 	if (cp != 0) {
-		*cp = 0;
 		return (cp + 1);
 	} else
 		return ("true");
@@ -285,7 +284,7 @@
 #endif
 
 void
-die(char *s)
+die(const char *s)
 {
 	fprintf(stderr, "%s", s);
 	exit (1);
Index: nam-salsa/view.cc
===================================================================
--- nam-salsa.orig/view.cc	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/view.cc	2024-10-06 10:19:09.000000000 +0200
@@ -51,7 +51,7 @@
 #include "packet.h"
 
 // Create list of font names and sizes
-static char * fontName[NFONT] = {
+static const char * fontName[NFONT] = {
   "-adobe-times-medium-r-normal-*-8-*-*-*-*-*-*-*",
   "-adobe-times-medium-r-normal-*-10-*-*-*-*-*-*-*",
   "-adobe-times-medium-r-normal-*-12-*-*-*-*-*-*-*",
Index: nam-salsa/address.cc
===================================================================
--- nam-salsa.orig/address.cc	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/address.cc	2024-10-06 10:19:09.000000000 +0200
@@ -182,7 +182,7 @@
 {
 	if (levels_ == 0) 
 		return atoi(str);
-	char *delim = ".";
+	const char *delim = ".";
 	char *tok;
 	int addr;
 	for (int i = 1; i <= levels_; i++) {
Index: nam-salsa/nam.h
===================================================================
--- nam-salsa.orig/nam.h	2024-10-06 10:17:24.000000000 +0200
+++ nam-salsa/nam.h	2024-10-06 10:19:09.000000000 +0200
@@ -21,5 +21,5 @@
 #ifndef nam_h
 #define nam_h
 
-extern void die(char *);
+extern void die(const char *);
 #endif