Skip to content

Commit

Permalink
Fix string truncation warning and refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
capehill committed Apr 19, 2019
1 parent 54cad40 commit 1cdbf4f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 32 deletions.
21 changes: 21 additions & 0 deletions common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "common.h"

#include <proto/dos.h>

#include <stdio.h>
#include <string.h>

void find_process_name2(struct Node * node, char * destination)
{
char buffer[NAME_LEN / 2] = { 0 };

if (node->ln_Type == NT_PROCESS) {
IDOS->GetCliProgramName(buffer, sizeof(buffer));
}

if (strlen(buffer) > 0) {
snprintf(destination, NAME_LEN, "%s '%s'", node->ln_Name, buffer);
} else {
snprintf(destination, NAME_LEN, "%s", node->ln_Name);
}
}
2 changes: 2 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#define NAME_LEN 64
#define MAX_CLIENTS 5

void find_process_name2(struct Node * node, char * destination);

void logLine(const char * fmt, ...) __attribute__ ((format (printf, 1, 2)));
void pause_log(void);
void resume_log(void);
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void remove_patches(void)

int main(int argc __attribute__((unused)), char* argv[] __attribute__((unused)))
{
logLine("glSnoop started. Built date: %s", __DATE__);
logLine("*** glSnoop started. Built date: %s ***", __DATE__);

if (already_running()) {
puts("glSnoop is already running");
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ else
DELETE = delete
endif

OBJS = main.o ogles2_module.o warp3dnova_module.o logger.o gui.o
OBJS = main.o ogles2_module.o warp3dnova_module.o logger.o gui.o common.o
CFLAGS = -Wall -Wextra -O3 -gstabs

%.o : %.c makefile
Expand Down
16 changes: 1 addition & 15 deletions ogles2_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

#include <proto/exec.h>
#include <proto/ogles2.h>
#include <proto/dos.h>

#include <stdio.h>
#include <string.h>

struct Library* OGLES2Base;

Expand Down Expand Up @@ -55,19 +53,7 @@ static void patch_ogles2_functions(struct Ogles2Context *);

static void find_process_name(struct Ogles2Context * context)
{
struct Node * node = (struct Node *)context->task;

if (node->ln_Type == NT_PROCESS) {
char buffer[32];

if (IDOS->GetCliProgramName(buffer, sizeof(buffer)) == FALSE) {
strncpy(context->name, node->ln_Name, NAME_LEN);
} else {
snprintf(context->name, NAME_LEN, "%s '%s'", node->ln_Name, buffer);
}
} else {
strncpy(context->name, node->ln_Name, NAME_LEN);
}
find_process_name2((struct Node *)context->task, context->name);
}

static BOOL open_ogles2_library(void)
Expand Down
16 changes: 1 addition & 15 deletions warp3dnova_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

#include <proto/exec.h>
#include <proto/warp3dnova.h>
#include <proto/dos.h>

#include <stdio.h>
#include <string.h>

struct Library* Warp3DNovaBase;
struct Interface* IWarp3DNova;
Expand Down Expand Up @@ -90,19 +88,7 @@ static void close_warp3dnova_library()

static void find_process_name(struct NovaContext * context)
{
struct Node * node = (struct Node *)context->task;

if (node->ln_Type == NT_PROCESS) {
char buffer[32];

if (IDOS->GetCliProgramName(buffer, sizeof(buffer)) == FALSE) {
strncpy(context->name, node->ln_Name, NAME_LEN);
} else {
snprintf(context->name, NAME_LEN, "%s '%s'", node->ln_Name, buffer);
}
} else {
strncpy(context->name, node->ln_Name, NAME_LEN);
}
find_process_name2((struct Node *)context->task, context->name);
}

static struct NovaContext* find_context(struct W3DN_Context_s* context)
Expand Down

0 comments on commit 1cdbf4f

Please sign in to comment.