vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / screen_savers / nebula / DrawStars.c
blob0bcb9c031ccbd2fe85b1f2c9882fad2efdc6682f
1 /*
2 * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Copyright 2015, Augustin Cavalier <waddlesplash>. All rights reserved.
4 * Distributed under the terms of the MIT License.
6 * Effect from corTeX / Optimum.
7 */
9 #include <SupportDefs.h>
11 #include "DrawStars.h"
14 // Hand-translated from x86 assembly.
15 /* draw a star (5 pixels) */
16 void draw_stars(int star_width, char* dstParam, char incParam)
18 unsigned char* dst;
19 unsigned char inc, al, cl;
20 dst = (unsigned char*)dstParam;
21 inc = (unsigned char)incParam;
23 dst[star_width] += inc;
24 if (dst[star_width] < inc) {
25 // Overflowed.
26 dst[star_width] = 255;
29 inc >>= 1;
30 cl = dst[star_width - 1];
31 cl += inc;
32 if (cl < inc) {
33 *dst = 255;
34 dst[star_width - 1] = 255;
35 } else {
36 al = *dst;
37 al += inc;
38 if (al >= inc)
39 *dst = al;
40 else
41 *dst = 255;
42 dst[star_width - 1] = cl;
45 al = dst[star_width * 2];
46 cl = dst[star_width + 1];
47 al += inc;
48 cl += inc;
49 if (al < inc) {
50 if (cl >= inc) {
51 dst[star_width * 2] = 255;
52 dst[star_width + 1] = cl;
53 return;
55 } else {
56 if (cl >= inc) {
57 dst[star_width * 2] = al;
58 dst[star_width + 1] = cl;
59 return;
63 dst[star_width * 2] = 255;
64 dst[star_width + 1] = 255;