diff options
| author | Ray <[email protected]> | 2018-10-10 23:55:36 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2018-10-10 23:55:36 +0200 |
| commit | 126ab49221ff4cc988ed83efc110d88e96c7f962 (patch) | |
| tree | 52f5b69d58f840389519bf68ea8a5c455f53c794 /src | |
| parent | 64778e8cd898c9d03b188853343af1369cfd0ddc (diff) | |
| download | raylib-126ab49221ff4cc988ed83efc110d88e96c7f962.tar.gz raylib-126ab49221ff4cc988ed83efc110d88e96c7f962.zip | |
Minor tweaks
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 3 | ||||
| -rw-r--r-- | src/rlgl.h | 14 | ||||
| -rw-r--r-- | src/textures.c | 2 |
3 files changed, 8 insertions, 11 deletions
@@ -1569,8 +1569,9 @@ const char *GetDirectoryPath(const char *fileName) lastSlash = strprbrk(fileName, "\\/"); if (!lastSlash) return NULL; + // NOTE: Be careful, strncpy() is not safe, it does not care about '\0' strncpy(filePath, fileName, strlen(fileName) - (strlen(lastSlash) - 1)); - filePath[strlen(fileName) - strlen(lastSlash)] = '\0'; + filePath[strlen(fileName) - strlen(lastSlash)] = '\0'; // Add '\0' manually return filePath; } @@ -1631,17 +1631,13 @@ void rlglInit(int width, int height) #elif defined(GRAPHICS_API_OPENGL_ES2) char *extensions = (char *)glGetString(GL_EXTENSIONS); // One big const string - // NOTE: We have to duplicate string because glGetString() returns a const value - // If not duplicated, it fails in some systems (Raspberry Pi) - // Equivalent to function: char *strdup(const char *str) - char *extensionsDup; - size_t len = strlen(extensions) + 1; - void *newstr = malloc(len); - if (newstr == NULL) extensionsDup = NULL; - extensionsDup = (char *)memcpy(newstr, extensions, len); + // NOTE: We have to duplicate string because glGetString() returns a const string + int len = strlen(extensions) + 1; + char *extensionsDup = (char *)malloc(len); + strcpy(extensionsDup, extensions); // NOTE: String could be splitted using strtok() function (string.h) - // NOTE: strtok() modifies the received string, it can not be const + // NOTE: strtok() modifies the passed string, it can not be const char *extList[512]; // Allocate 512 strings pointers (2 KB) diff --git a/src/textures.c b/src/textures.c index 7ee07d12..4c276324 100644 --- a/src/textures.c +++ b/src/textures.c @@ -323,7 +323,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int // NOTE: fread() returns num read elements instead of bytes, // to get bytes we need to read (1 byte size, elements) instead of (x byte size, 1 element) - size_t bytes = fread(image.data, 1, size, rawFile); + int bytes = fread(image.data, 1, size, rawFile); // Check if data has been read successfully if (bytes < size) |
