-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from dloebl/fix-32-bit-crash
Fix a potential crash on 32-bit systems
- Loading branch information
Showing
5 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
#include "cgif.h" | ||
|
||
#define WIDTH 3000 | ||
#define HEIGHT 3000 | ||
|
||
static uint64_t seed; | ||
|
||
// unsigned integer overflow expected | ||
__attribute__((no_sanitize("integer"))) | ||
int psdrand(void) { | ||
// simple pseudo random function from musl libc | ||
seed = 6364136223846793005ULL * seed + 1; | ||
return seed >> 33; | ||
} | ||
|
||
int main(void) { | ||
CGIF* pGIF; | ||
CGIF_Config gConfig; | ||
CGIF_FrameConfig fConfig; | ||
uint8_t* pImageData; | ||
cgif_result r; | ||
uint8_t aPalette[256 * 3]; | ||
|
||
seed = 22; | ||
for(int i = 0; i < 256; ++i) { | ||
aPalette[i * 3] = psdrand() % 256; | ||
aPalette[i * 3 + 1] = psdrand() % 256; | ||
aPalette[i * 3 + 2] = psdrand() % 256; | ||
} | ||
memset(&gConfig, 0, sizeof(CGIF_Config)); | ||
memset(&fConfig, 0, sizeof(CGIF_FrameConfig)); | ||
gConfig.width = WIDTH; | ||
gConfig.height = HEIGHT; | ||
gConfig.pGlobalPalette = aPalette; | ||
gConfig.numGlobalPaletteEntries = 256; | ||
gConfig.path = "noise256_large.gif"; | ||
// | ||
// create new GIF | ||
pGIF = cgif_newgif(&gConfig); | ||
if(pGIF == NULL) { | ||
fputs("failed to create new GIF via cgif_newgif()\n", stderr); | ||
return 1; | ||
} | ||
// | ||
// add frames to GIF | ||
pImageData = malloc(WIDTH * HEIGHT); | ||
for(int i = 0; i < WIDTH * HEIGHT; ++i) pImageData[i] = psdrand() % 256; | ||
fConfig.pImageData = pImageData; | ||
r = cgif_addframe(pGIF, &fConfig); | ||
free(pImageData); | ||
// | ||
// write GIF to file | ||
r = cgif_close(pGIF); // free allocated space at the end of the session | ||
|
||
// check for errors | ||
if(r != CGIF_OK) { | ||
fprintf(stderr, "failed to create GIF. error code: %d\n", r); | ||
return 2; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters