Skip to content

Commit

Permalink
tprintf: Make code reentrant and use less memory
Browse files Browse the repository at this point in the history
Reduce the maximum message size from 64 KiB to 2 KiB which still should
be large enought for trace messages.

Create the smaller message on the stack instead of using a global
array to allow reentrancy and to reduce the memory use of Tesseract.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed May 21, 2019
1 parent c926bdb commit 078a129
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/ccutil/tprintf.cpp
Expand Up @@ -2,7 +2,6 @@
* File: tprintf.cpp
* Description: Trace version of printf - portable between UX and NT
* Author: Phil Cheatle
* Created: Wed Jun 28 15:01:15 BST 1995
*
* (C) Copyright 1995, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -29,7 +28,7 @@
#include "strngs.h"
#include "tprintf.h"

#define MAX_MSG_LEN 65536
#define MAX_MSG_LEN 2048

static STRING_VAR(debug_file, "", "File to send tprintf output to");

Expand All @@ -42,7 +41,7 @@ DLLSYM void tprintf(const char *format, ...)
static FILE *debugfp = nullptr; // debug file
// debug window
int32_t offset = 0; // into message
static char msg[MAX_MSG_LEN + 1];
char msg[MAX_MSG_LEN + 1];

va_start(args, format); // variable list
// Format into msg
Expand Down

0 comments on commit 078a129

Please sign in to comment.