ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/utils.C
(Generate patch)

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.103 by root, Mon Dec 17 02:07:15 2012 UTC vs.
Revision 1.109 by root, Wed Dec 5 19:03:26 2018 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 6 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 7 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 8 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 9 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 10 * option) any later version.
41#include <glib.h> 42#include <glib.h>
42 43
43refcnt_base::refcnt_t refcnt_dummy; 44refcnt_base::refcnt_t refcnt_dummy;
44ssize_t slice_alloc; 45ssize_t slice_alloc;
45 46
46#if !GCC_VERSION(3,4)
47int least_significant_bit (uint32_t x)
48{
49 x &= -x; // this isolates the lowest bit
50
51 int r = 0;
52
53 if (x & 0xaaaaaaaa) r += 1;
54 if (x & 0xcccccccc) r += 2;
55 if (x & 0xf0f0f0f0) r += 4;
56 if (x & 0xff00ff00) r += 8;
57 if (x & 0xffff0000) r += 16;
58
59 return r;
60}
61#endif
62
63/******************************************************************************/ 47/******************************************************************************/
64 48
65/* Checks a player-provided string which will become the msg property of 49/* Checks a player-provided string which will become the msg property of
66 * an object for dangerous input. 50 * an object for dangerous input.
67 */ 51 */
68bool 52bool
69msg_is_safe (const char *msg) 53msg_is_safe (const char *msg)
70{ 54{
71 bool safe = true; 55 bool safe = true;
72 56
73 /* Trying to cheat by getting data into the object */ 57 /* Trying to cheat by getting data into the object */
130 114
131 LOG (llevError, "fork abort: %s\n", msg); 115 LOG (llevError, "fork abort: %s\n", msg);
132} 116}
133 117
134void * 118void *
135salloc_ (int n) throw (std::bad_alloc) 119salloc_ (int n)
136{ 120{
137 void *ptr = g_slice_alloc (n); 121 void *ptr = g_slice_alloc (n);
138 122
139 if (!ptr) 123 if (!ptr)
140 throw std::bad_alloc (); 124 throw std::bad_alloc ();
142 slice_alloc += n; 126 slice_alloc += n;
143 return ptr; 127 return ptr;
144} 128}
145 129
146void * 130void *
147salloc_ (int n, void *src) throw (std::bad_alloc) 131salloc_ (int n, void *src)
148{ 132{
149 void *ptr = salloc_ (n); 133 void *ptr = salloc_ (n);
150 134
151 if (src) 135 if (src)
152 memcpy (ptr, src, n); 136 memcpy (ptr, src, n);
179 163
180void 164void
181g_slice_free1 (unsigned long size, void *ptr) 165g_slice_free1 (unsigned long size, void *ptr)
182{ 166{
183 //fprintf (stderr, "g_slice_free %ld %p\n", size, ptr);//D 167 //fprintf (stderr, "g_slice_free %ld %p\n", size, ptr);//D
184 if (expect_true (ptr)) 168 if (ecb_expect_true (ptr))
185 { 169 {
186 unsigned long *p = (unsigned long *)ptr; 170 unsigned long *p = (unsigned long *)ptr;
187 unsigned long s = *--p ^ MAGIC; 171 unsigned long s = *--p ^ MAGIC;
188 172
189 if (size != (unsigned long)(*p ^ MAGIC)) 173 if (size != (unsigned long)(*p ^ MAGIC))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines