Discussion:
Simple console ANSI C program crashes Win64 system upon start?
(too old to reply)
Harry Potter
2023-07-27 22:01:26 UTC
Permalink
Hi! I am working on a 32-bit mode program in ANSI C format using the Digital Mars C compiler. I was unable to get the version, but it's probably a few years old. The program is to compress strings for certain old 8-bit computers such that a target program can print out individual strings without referring to other strings. I'm working on using tokenization, RLE of spaces (tabs of given sizes) and ways to compress literals without full-blown Huffman. The problem is that, as soon as the program starts, the computer crashes with a BSOD. :( I didn't record the stop code. I don't even get the text that is supposed to display upon start-up. I attached the whole main module:
---------------------------
/***********************************************************************
*
* Individual module for the ANSI compiler.
*
* The template for this file was created by TempC Module Creator by
* Joseph Rose. This template can be used in your programs, provided
* you mention TempC in your software's documentation. If this source
* code is distributed, this copyright must be included in the file.
*
***********************************************************************/

#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include "in.h"
#include "buffer.h"

struct __indata {
enum {
sysCBM,
sysAtari,
sysApple2
} sys;
char toktype[16];
char littype[16];
struct {
unsigned docurchar;
char curcharname[32];
unsigned docharptr;
char curptrname[32];
} dozp;
char outname[256];
} indata;

unsigned loadfile (char* name);

int main (int argc, char** argv)
{
char c, c2;
struct string_buffer * atstring;
//Enable the following line and declare
//char programname[128]; if the executable path is
//needed:
//strcpy (programname, argv[0]);
//Analyze the command line:
puts ("Ready to start program!"); getchar();
while (--argc) {
//Advance to next arg.
argv++;
printf ("Para %s\n", *argv); getchar();
//Is it a switch?
if (argv[0][0]=='-') {
//Process switch:
putchar ((argv[0][1])); puts(""); getchar();
switch (argv[0][1]) {
case 't':
//puts ("t switch processed.");
--argc; argv++;
if (!strcmp(*argv, "cbm")) indata.sys=sysCBM;
else if (!strcmp(*argv, "apple2")) indata.sys=sysApple2;
else if (!strcmp(*argv, "atari")) indata.sys=sysAtari;
else {
puts ("Error parsing cmdline: unrecognized target system.");
return 1;
}
break;
case 'o':
--argc; argv++;
strcpy (indata.outname, *argv);
break;
case 'c':
// switch (argv[0][2]) {
// case 't':
// case 'l':
// }
c=argv[0][2];
--argc; argv++;
if (c=='t') strcpy (indata.toktype,*argv);
else if (c=='l') strcpy (indata.littype,*argv);
else {
puts ("Error parsing cmdline: unrecognized compression type.");
return 1;
}
break;

case '?': //Print help.
puts ("Help."); return 0;
default: //Trap bad switch.
printf ("Bad switch: %c.", argv[0][1]); return 1;
}
} else { //Handle filename:
//printf ("File: %s\n", argv[0]);
--argc; argv++;
puts (*argv); getchar();
if (loadfile(*argv)) {
printf ("Error in file \"%s\"\n", *argv);
return 2;
}
}
}
// if ()
puts ("Ready to print strings!"); getchar();
if (!strings) {
puts ("No input strings!"); return 2;
}
atstring=strings;
do {
puts (atstring->name);
puts ("----------------");
puts (atstring->in);
printf (">>> len=%d\n", atstring->inlen);
puts ("=================");
atstring=atstring->next;
} while (atstring);
puts ("---end!");
getchar();
return 0;
}
----------------------------------
and the line that compiles the program:
----------------------------------
c:\dm\bin\dmc buffer.c in.c main.c -o -mn -4 -optok_comp.exe
----------------------------------
BTW, What can I do to better my versions of literal compression? I have ways to compress to 7 bits per character and 5 bits per character, can add a bit to some 5-bit codes to add more functionality there, can tag two bits to token specifiers on the literal compression techniques to bring the total of supported tokens to 128, and, if a run of spaces is not a tab, can shorten the length to 3 bits. Also, is there a way to better tokenization? Remember that a string can't reference another string except for tokens, and this is for an 8-bit computer.
JJ
2023-07-28 04:55:49 UTC
Permalink
Post by Harry Potter
Hi! I am working on a 32-bit mode program in ANSI C format using the
Digital Mars C compiler. I was unable to get the version, but it's
probably a few years old. The program is to compress strings for certain
old 8-bit computers such that a target program can print out individual
strings without referring to other strings. I'm working on using
tokenization, RLE of spaces (tabs of given sizes) and ways to compress
literals without full-blown Huffman. The problem is that, as soon as the
program starts, the computer crashes with a BSOD. :( I didn't record
the stop code. I don't even get the text that is supposed to display
Just debug it.

The progress of all of your projects will be very slow or even end up stuck
if you don't know how to debug a program.
Paul Edwards
2023-07-28 11:41:23 UTC
Permalink
Post by Harry Potter
I don't even get the text that is supposed to display upon start-up.
Does a "hello world" program work?

BFN. Paul.
Harry Potter
2023-07-28 11:56:35 UTC
Permalink
Post by Paul Edwards
Does a "hello world" program work?
I tried one using the same settings as the problem code, and it worked.
Paul Edwards
2023-07-28 12:17:38 UTC
Permalink
Post by Harry Potter
Post by Paul Edwards
Does a "hello world" program work?
I tried one using the same settings as the problem code, and it worked.
Ok, two things to try:

1. Make the "main" program in the problem program the
first thing that is compiled. Currently it is the last of 3 things.

2. Put a "return 0" after the print on startup in the main
program, while leaving everything else the same.

BFN. Paul.
Harry Potter
2023-07-28 13:46:22 UTC
Permalink
Post by Paul Edwards
1. Make the "main" program in the problem program the
first thing that is compiled. Currently it is the last of 3 things.
2. Put a "return 0" after the print on startup in the main
program, while leaving everything else the same.
Thank you. I'll try them soon. :)
Harry Potter
2023-07-28 15:01:43 UTC
Permalink
I tried both of your suggestions. Same result. Could it be the usage of calloc()?
Paul Edwards
2023-07-28 15:31:00 UTC
Permalink
I tried both of your suggestions. Same result.
Same result as the hello world that worked, or the original which failed?
Could it be the usage of calloc()?
If it failed, then calloc shouldn't be being hit.

Try combining both suggestions - ie put main as the first
file, and do a return 0 after the first printf.

Also send both the main.c code and the compile command
you are using so that I can see again.

Also send the working hello world - both code and compile command.

BFN. Paul.
Harry Potter
2023-07-28 23:08:49 UTC
Permalink
Post by Paul Edwards
Try combining both suggestions - ie put main as the first
file, and do a return 0 after the first printf.
I did. It didn'yt work. :(
Post by Paul Edwards
Also send both the main.c code and the compile command
you are using so that I can see again.
Also send the working hello world - both code and compile command.
The problem code:
----------------------------------
/***********************************************************************
*
* Individual module for the ANSI compiler.
*
* The template for this file was created by TempC Module Creator by
* Joseph Rose. This template can be used in your programs, provided
* you mention TempC in your software's documentation. If this source
* code is distributed, this copyright must be included in the file.
*
***********************************************************************/

#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include "in.h"
#include "buffer.h"

struct __indata {
enum {
sysCBM,
sysAtari,
sysApple2
} sys;
char toktype[16];
char littype[16];
struct {
unsigned docurchar;
char curcharname[32];
unsigned docharptr;
char curptrname[32];
} dozp;
char outname[256];
} indata;

unsigned loadfile (char* name);

int main (int argc, char** argv)
{
char c, c2;
struct string_buffer * atstring;
//Enable the following line and declare
//char programname[128]; if the executable path is
//needed:
//strcpy (programname, argv[0]);
//Analyze the command line:
puts ("Ready to start program!"); getchar();
while (--argc) {
//Advance to next arg.
argv++;
printf ("Para %s\n", *argv); getchar();
//Is it a switch?
if (argv[0][0]=='-') {
//Process switch:
putchar ((argv[0][1])); puts(""); getchar();
switch (argv[0][1]) {
case 't':
//puts ("t switch processed.");
--argc; argv++;
if (!strcmp(*argv, "cbm")) indata.sys=sysCBM;
else if (!strcmp(*argv, "apple2")) indata.sys=sysApple2;
else if (!strcmp(*argv, "atari")) indata.sys=sysAtari;
else {
puts ("Error parsing cmdline: unrecognized target system.");
return 1;
}
break;
case 'o':
--argc; argv++;
strcpy (indata.outname, *argv);
break;
case 'c':
// switch (argv[0][2]) {
// case 't':
// case 'l':
// }
c=argv[0][2];
--argc; argv++;
if (c=='t') strcpy (indata.toktype,*argv);
else if (c=='l') strcpy (indata.littype,*argv);
else {
puts ("Error parsing cmdline: unrecognized compression type.");
return 1;
}
break;

case '?': //Print help.
puts ("Help."); return 0;
default: //Trap bad switch.
printf ("Bad switch: %c.", argv[0][1]); return 1;
}
} else { //Handle filename:
//printf ("File: %s\n", argv[0]);
//--argc; argv++;
puts (*argv); getchar();
if (loadfile(*argv)) {
printf ("Error in file \"%s\"\n", *argv);
return 2;
}
}
}
// if ()
puts ("Ready to print strings!"); getchar();
if (!strings) {
puts ("No input strings!"); return 2;
}
atstring=strings;
do {
puts (atstring->name);
puts ("----------------");
puts (atstring->in);
printf (">>> len=%d\n", atstring->inlen);
puts ("=================");
atstring=atstring->next;
} while (atstring);
puts ("---end!");
getchar();
return 0;
}

----------------------------------
The compile command:
------------------------------
c:\dm\bin\dmc buffer.c in.c main.c -o -mn -4 -optok_comp.exe
-------------------------------------
The Hello, world example:
--------------------------------------
/***********************************************************************
*
* Individual module for the ANSI compiler.
*
* The template for this file was created by TempC Module Creator by
* Joseph Rose. This template can be used in your programs, provided
* you mention TempC in your software's documentation. If this source
* code is distributed, this copyright must be included in the file.
*
***********************************************************************/

#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>


int main (int argc, char** argv)
{
//Enable the following line and declare
//char programname[128]; if the executable path is
//needed:
//strcpy (programname, argv[0]);
//Analyze the command line:
puts ("Hello, world!"); getchar();
return 0;
}

------------------------------
Its compile command:
---------------------------------
c:\dm\bin\dmc main.c -o -mn -4 -otet.exe
---------------------------------
BTW, it seems to work on a Win7/64 laptop. I'm going to try to port this code to Open Watcom soon....
Harry Potter
2023-07-28 23:27:45 UTC
Permalink
The same problem occurred with OW. :(
Paul Edwards
2023-07-30 06:59:43 UTC
Permalink
Post by Harry Potter
Post by Paul Edwards
Also send both the main.c code and the compile command
you are using so that I can see again.
puts ("Ready to start program!"); getchar();
Was my suggestion unclear?

I asked you to put a return 0 after that puts. I don't see it.

BFN. Paul.
Harry Potter
2023-07-30 10:05:33 UTC
Permalink
Post by Paul Edwards
I asked you to put a return 0 after that puts. I don't see it.
I plan to try that later today.
Harry Potter
2023-07-30 23:04:15 UTC
Permalink
I tried adding "return 0;" to the beginning of the program and got the same problem, but I have more information: IIRC, it was a system service exception, but I didn't commit the causing program to memory. Also, I got another BSOD stating I think a DMA exception, and, upon a second restart, the system wouldn't start up. :( Then Windows performed auto fix mode. I have it do nothing, and the system started behaving properly again at that point.
Paul Edwards
2023-07-31 00:01:01 UTC
Permalink
Post by Harry Potter
I tried adding "return 0;" to the beginning of the program and got
the same problem, but I have more information: IIRC, it was a
system service exception, but I didn't commit the causing program
to memory. Also, I got another BSOD stating I think a DMA
exception, and, upon a second restart, the system wouldn't start
up. :( Then Windows performed auto fix mode. I have it do nothing,
and the system started behaving properly again at that point.
By "behaving properly" do you mean the problem with your
program has been solved and you no longer need help?

BFN. Paul.
Harry Potter
2023-07-31 10:07:45 UTC
Permalink
Post by Paul Edwards
By "behaving properly" do you mean the problem with your
program has been solved and you no longer need help?
No, just that Windows started behaving properly again in the end.
Paul Edwards
2023-08-01 01:43:19 UTC
Permalink
Post by Harry Potter
Post by Paul Edwards
By "behaving properly" do you mean the problem with your
program has been solved and you no longer need help?
No, just that Windows started behaving properly again in the end.
Ok, so you still have an issue.

Two things. You showed me this compile command:

c:\dm\bin\dmc buffer.c in.c main.c -o -mn -4 -optok_comp.exe

I asked you to put main.c first, didn't I?

So please show me a fresh compile command, and also show me
fresh source code that shows the return in the place that I asked
you to put it.

BFN. Paul.
Harry Potter
2023-08-03 21:24:07 UTC
Permalink
I just tried your suggestions. No change. :( Following are the current main() definition:
--------------------------------
int main (int argc, char** argv)
{
char c, c2;
struct string_buffer * atstring;
//Enable the following line and declare
//char programname[128]; if the executable path is
//needed:
//strcpy (programname, argv[0]);
//Analyze the command line:
return 0;
puts ("Ready to start program!"); getchar();
while (--argc) {
//Advance to next arg.
argv++;
printf ("Para %s\n", *argv); getchar();
//Is it a switch?
if (argv[0][0]=='-') {
//Process switch:
putchar ((argv[0][1])); puts(""); getchar();
switch (argv[0][1]) {
case 't':
//puts ("t switch processed.");
--argc; argv++;
if (!strcmp(*argv, "cbm")) indata.sys=sysCBM;
else if (!strcmp(*argv, "apple2")) indata.sys=sysApple2;
else if (!strcmp(*argv, "atari")) indata.sys=sysAtari;
else {
puts ("Error parsing cmdline: unrecognized target system.");
return 1;
}
break;
case 'o':
--argc; argv++;
strcpy (indata.outname, *argv);
break;
case 'c':
// switch (argv[0][2]) {
// case 't':
// case 'l':
// }
c=argv[0][2];
--argc; argv++;
if (c=='t') strcpy (indata.toktype,*argv);
else if (c=='l') strcpy (indata.littype,*argv);
else {
puts ("Error parsing cmdline: unrecognized compression type.");
return 1;
}
break;

case '?': //Print help.
puts ("Help."); return 0;
default: //Trap bad switch.
printf ("Bad switch: %c.", argv[0][1]); return 1;
}
} else { //Handle filename:
//printf ("File: %s\n", argv[0]);
//--argc; argv++;
puts (*argv); getchar();
if (loadfile(*argv)) {
printf ("Error in file \"%s\"\n", *argv);
return 2;
}
}
}
// if ()
puts ("Ready to print strings!"); getchar();
if (!strings) {
puts ("No input strings!"); return 2;
}
atstring=strings;
do {
puts (atstring->name);
puts ("----------------");
puts (atstring->in);
printf (">>> len=%d\n", atstring->inlen);
puts ("=================");
atstring=atstring->next;
} while (atstring);
puts ("---end!");
getchar();
return 0;
}

---------------------------------
and the command line:
------------------------------------------
c:\dm\bin\dmc main.c buffer.c in.c -o -mn -4 -optok_comp.exe
Paul Edwards
2023-08-06 10:36:13 UTC
Permalink
Post by Harry Potter
--------------------------------
int main (int argc, char** argv)
{
char c, c2;
struct string_buffer * atstring;
//Enable the following line and declare
//char programname[128]; if the executable path is
//strcpy (programname, argv[0]);
return 0;
puts ("Ready to start program!"); getchar();
Ok, so by "no change" I assume that means you are still
getting the BSOD, even though this program is meant to
simply exit immediately.
Post by Harry Potter
c:\dm\bin\dmc main.c buffer.c in.c -o -mn -4 -optok_comp.exe
And the compile command is in the right order at least.

Ok, so next thing to do is put:

return 0;
#if 0
puts ("Ready to start program!"); getchar();
...
#endif

To comment out all other code except for one returning "}"
and see what happens - with the same compile command,
ie compiling and (nominally) linking in two extra files that
aren't ever called.

BFN. Paul.
legalize+ (Richard)
2023-08-08 15:26:51 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by Harry Potter
I just tried your suggestions. No change. :(
Have you tried stepping through it in the debugger?
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Harry Potter
2023-08-09 23:39:13 UTC
Permalink
Post by legalize+ (Richard)
Have you tried stepping through it in the debugger?
I just tried Open Watcom's debugger and got a "Cannot load trap file (%s) 'std.dll'" error. :(
Harry Potter
2023-08-12 13:06:55 UTC
Permalink
Never mind: I got it to work. :) Maybe there's a bug with DMC. I tried Open Watcom. It didn't work. However, when I copied the program to my hard drive--it was compressed on a floppy--it started working. :) I think OW has a bug with compiled programs on a different drive than OW's compiler.
Loading...