ObjFW  Diff

Differences From Artifact [d6b3535b02]:

To Artifact [54579841e3]:

  • File src/OFObject.m — part of check-in [c1fe4b2b77] at 2020-07-12 09:49:35 on branch trunk — Make of_random() a function

    When arc4random() is unavailable, either random() or rand() is used and
    both need to be seeded. If of_random() is a macro, it needs to be
    (re)seeded every time, as it's unknown whether it has already been
    seeded. As it is seeded with gettimeofday() due to the lack of a better
    initial seed, this means every call returns the first state for the
    current time, which is very predictable. random() and rand() are both
    not cryptographic, but this should at least make it a little bit better
    now. (user: js, size: 30665) [annotate] [blame] [check-ins using]


99
100
101
102
103
104
105

































106
107
108
109
110
111
112
#define PRE_MEM(mem) ((struct pre_mem *)(void *)((char *)mem - PRE_MEM_ALIGN))

static struct {
	Class isa;
} allocFailedException;

uint32_t of_hash_seed;


































static const char *
typeEncodingForSelector(Class class, SEL selector)
{
	Method method;

	if ((method = class_getInstanceMethod(class, selector)) == NULL)







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
#define PRE_MEM(mem) ((struct pre_mem *)(void *)((char *)mem - PRE_MEM_ALIGN))

static struct {
	Class isa;
} allocFailedException;

uint32_t of_hash_seed;

#ifndef HAVE_ARC4RANDOM
static void
initRandom(void)
{
	struct timeval tv;

# ifdef HAVE_RANDOM
	gettimeofday(&tv, NULL);
	srandom((unsigned)(tv.tv_sec ^ tv.tv_usec));
# else
	gettimeofday(&tv, NULL);
	srand((unsigned)(tv.tv_sec ^ tv.tv_usec));
# endif
}
#endif

uint32_t
of_random(void)
{
#ifdef HAVE_ARC4RANDOM
	return arc4random();
#else
	static of_once_t onceControl;

	of_once(&onceControl, initRandom);
# ifdef HAVE_RANDOM
	return (((uint32_t)(random()) << 16) | ((uint32_t)(random()) & 0xFFFF));
# else
	return (((uint32_t)(rand()) << 16) | ((uint32_t)(rand()) & 0xFFFF));
# endif
#endif
}

static const char *
typeEncodingForSelector(Class class, SEL selector)
{
	Method method;

	if ((method = class_getInstanceMethod(class, selector)) == NULL)