From: "Philippe Lorin" <palpalpalpal@hotmail.com>
Subject: extra characters displayed at ends of lines
Date: Thu, 16 Sep 2004 14:46:39 +0000 [thread overview]
Message-ID: <BAY13-F34YD6pR1h8Fw00008437@hotmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1135 bytes --]
In GNU Emacs 21.2.1 (i386-msvc-windows98.2222)
of 2002-03-19 on buffy
configured using `configure --with-msvc (12.00)'
Important settings:
value of $LC_ALL: nil
value of $LC_COLLATE: nil
value of $LC_CTYPE: nil
value of $LC_MESSAGES: nil
value of $LC_MONETARY: nil
value of $LC_NUMERIC: nil
value of $LC_TIME: nil
value of $LANG: fra
locale-coding-system: iso-latin-1
default-enable-multibyte-characters: t
How to make the bug happen:
Have the attached file ready to be visited.
Using the following .emacs (without the tags of course):
<.emacs>
; Don't wrap lines
(set-default 'truncate-lines t)
; Frame position
(add-to-list 'default-frame-alist '(width . 122))
</.emacs>
Do this:
C-x C-f <attached file name, apparently the bug doesn't care about what the
file name is>
C-s . s i z e C-s C-s
Here is the bug. The display is incorrect. There are extra characters beyond
the actual ends of lines. To see what it should be like, just type:
C-l
_________________________________________________________________
Dialoguez en direct et gratuitement avec vos amis sur
http://g.msn.fr/FR1001/866 MSN Messenger !
[-- Attachment #2: zubuzubuz --]
[-- Type: text/plain, Size: 6568 bytes --]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <allegro.h>
#include "GMbase/system.h"
#include "GMbase/systems/Allegro/util.h"
#include "GMbase/systems/Allegro/error.h"
#include "GMbase/systems/Allegro/malloc.h"
#undef malloc
#undef realloc
#undef free
typedef struct {
void* result; // pointer returned to the caller: this is the pointer to
the data without the fences
size_t size; // size asked by the caller: this is the size of the data
without the fences
bool realloced; // whether this pointer was ever realloced
int line;
char* file;
} Malloc_trace;
#define nb_max_malloced_pointers 4096
static Malloc_trace traces[nb_max_malloced_pointers];
static int nb_malloced_pointers = 0;
static char tmp_string[1024];
static size_t max_size_reached;
static size_t current_size;
#define fence_size (32 * sizeof(char))
#define fence_value ((char) 223)
/** Whether the closing function for this subsystem was called or this
subsystem is not initialized. */
static bool proper_end_called = true;
static void end() {
if (! proper_end_called) {
System_internal_error(false, "Malloc subsystem not ended.\n");
PrivateSystem_malloc_end();
}
}
void System_log_memory_usage() {
int nb_bytes;
nb_bytes = max_size_reached / sizeof(char);
System_log("Maximum memory usage was: ");
if (nb_bytes >= 1*1024*1024) {
System_log("%.1f MB (%d bytes).\n", ((float) nb_bytes) / (1024 * 1024),
nb_bytes);
} else if (nb_bytes >= 3*1024) {
System_log("%.1f kB (%d bytes).\n", ((float) nb_bytes) / 1024, nb_bytes);
} else {
System_log("%d bytes.\n", nb_bytes);
}
}
void PrivateSystem_malloc_end() {
int i;
proper_end_called = true;
System_log_memory_usage();
for (i = 0; i < nb_malloced_pointers; i++) {
System_internal_error(false, "Memory leak: Area malloced at %s: %d (size:
%d) was never freed.\n", traces[i].file, traces[i].line, traces[i].size);
}
}
void PrivateSystem_malloc_init() {
current_size = 0;
max_size_reached = 0;
proper_end_called = false;
atexit(end);
}
void* _System_malloc(char* file, int line, size_t size) {
static bool too_many_mallocs = false;
void* mem;
if (size == 0) {
return NULL;
}
mem = malloc(size + 2*fence_size);
//debug_log("malloc(%d) at %s:%d -> %p\n", size, file, line, mem);
if (mem != NULL) {
// Register mem
if (! too_many_mallocs) {
if (nb_malloced_pointers >= nb_max_malloced_pointers) {
PrivateSystem_internal_error(false, "Too many mallocs.\n");
too_many_mallocs = true;
} else {
traces[nb_malloced_pointers].result = mem + fence_size;
traces[nb_malloced_pointers].size = size;
traces[nb_malloced_pointers].realloced = false;
traces[nb_malloced_pointers].line = line;
traces[nb_malloced_pointers].file = file;
current_size += size;
if (current_size > max_size_reached) {
max_size_reached = current_size;
}
nb_malloced_pointers++;
}
}
memset(mem, fence_value, fence_size);
memset(mem + fence_size + size, fence_value, fence_size);
System_check_malloc(mem + fence_size, "Malloc auto-check\n");
return mem + fence_size;
}
// TODO handle this properly
System_error(true, "Not enough memory.\n");
return NULL; // compiler candy
}
void* _System_realloc(char* file, int line, void* p, size_t size) {
void* mem;
if (p == NULL) {
return System_malloc(size);
}
System_check_malloc(p, "Realloc check before work\n");
mem = realloc(p - fence_size, size + 2*fence_size);
//debug_log("realloc(%p, %d) at %s:%d -> %p\n", p, size, file, line, mem);
if (mem != NULL) {
int i;
for (i = 0; i < nb_malloced_pointers; i++) {
if (p == traces[i].result) {
current_size += size - traces[i].size;
if (current_size > max_size_reached) {
max_size_reached = current_size;
}
traces[i].result = mem + fence_size;
traces[i].size = size;
traces[i].realloced = true;
break;
}
}
if (i == nb_malloced_pointers) {
System_internal_error(false, "%s: %d: Bad pointer realloced (this pointer
was never malloced).\n", file, line);
}
memset(mem, fence_value, fence_size);
memset(mem + fence_size + size, fence_value, fence_size);
System_check_malloc(mem + fence_size, "Realloc auto-check\n");
return mem + fence_size;
}
// TODO handle this properly
System_error(true, "Not enough memory.\n");
return NULL; // compiler candy
}
void _System_free(char* file, int line, void* p) {
int i;
//debug_log("free(%p) at %s:%d\n", p, file, line);
if (p == NULL) {
return;
}
System_check_malloc(p, "Free check before work\n");
for (i = 0; i < nb_malloced_pointers; i++) {
if (p == traces[i].result) {
free(p);
nb_malloced_pointers--;
traces[i] = traces[nb_malloced_pointers];
//debug_log("}free\n");
return;
}
}
//debug_log("}free:ERROR\n");
System_internal_error(false, "%s: %d: Bad pointer freed. This pointer was
never malloced.\n", file, line);
}
/**
* If p is inside any previously malloced memory, returns the corresponding
trace's index.
* Otherwise returns -1.
// * Returns whether p is inside any previously malloced memory. Returns
true when p == NULL.
*/
static int _check_malloc(void* p) {
int i;
if (p == NULL) return -1;
for (i = 0; i < nb_malloced_pointers; i++) {
if ((p >= traces[i].result) && (p < traces[i].result + traces[i].size)) {
return i;
}
}
return -1;
}
void System_check_malloc(void* p, char* format, ...) {
int trace_index;
if (p == NULL) return;
trace_index = _check_malloc(p);
if (trace_index == -1) {
sprintf(tmp_string, "Bad pointer: ");
sprintf_args(format, tmp_string + strlen(tmp_string));
System_internal_error(true, tmp_string);
} else {
int i;
for (i = 0; i < fence_size / sizeof(char); i++) {
if ((((char*) p) - fence_size + i != fence_value) || (((char*) p) +
traces[trace_index].size + i != fence_value)) {
sprintf(tmp_string, "Malloced area overflown: Memory around area
malloced at %s: %d (size: %d) was illegally written into.\n",
traces[trace_index].file, traces[trace_index].line,
traces[trace_index].size);
sprintf_args(format, tmp_string + strlen(tmp_string));
System_internal_error(true, tmp_string);
}
}
}
}
/*
// MEMC
static bool is_memc_on = false;
void set_memc_on() {
is_memc_on = true;
}
void set_memc_off() {
is_memc_on = false;
}
void memc_check(void* p, char* file, long line) {
if (p == NULL) {
debug_log("NULL pointer at %s:%d\n", file, line);
}
if (! is_memc_on) return;
if (! _check_malloc(p)) {
debug_log("Pointer to non-malloced area at %s:%d\n", file, line);
}
}
*/
[-- Attachment #3: Type: text/plain, Size: 149 bytes --]
_______________________________________________
Bug-gnu-emacs mailing list
Bug-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs
next reply other threads:[~2004-09-16 14:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-16 14:46 Philippe Lorin [this message]
[not found] <mailman.2997.1095346832.1998.bug-gnu-emacs@gnu.org>
2004-09-20 20:32 ` extra characters displayed at ends of lines Jason Rumney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BAY13-F34YD6pR1h8Fw00008437@hotmail.com \
--to=palpalpalpal@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).