• Simple console ANSI C program crashes Win64 system upon start?

    From Harry Potter@21:1/5 to All on Thu Jul 27 15:01:26 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to Harry Potter on Fri Jul 28 11:55:49 2023
    On Thu, 27 Jul 2023 15:01:26 -0700 (PDT), Harry Potter wrote:
    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:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Edwards@21:1/5 to Harry Potter on Fri Jul 28 04:41:23 2023
    On Friday, July 28, 2023 at 6:01:29 AM UTC+8, Harry Potter wrote:

    I don't even get the text that is supposed to display upon start-up.

    Does a "hello world" program work?

    BFN. Paul.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to Paul Edwards on Fri Jul 28 04:56:35 2023
    On Friday, July 28, 2023 at 7:41:25 AM UTC-4, Paul Edwards wrote:
    Does a "hello world" program work?

    I tried one using the same settings as the problem code, and it worked.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Edwards@21:1/5 to Harry Potter on Fri Jul 28 05:17:38 2023
    On Friday, July 28, 2023 at 7:56:37 PM UTC+8, Harry Potter wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to Paul Edwards on Fri Jul 28 06:46:22 2023
    On Friday, July 28, 2023 at 8:17:41 AM UTC-4, Paul Edwards wrote:
    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. :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to All on Fri Jul 28 08:01:43 2023
    I tried both of your suggestions. Same result. Could it be the usage of calloc()?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Edwards@21:1/5 to Harry Potter on Fri Jul 28 08:31:00 2023
    On Friday, July 28, 2023 at 11:01:45 PM UTC+8, Harry Potter wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to Paul Edwards on Fri Jul 28 16:08:49 2023
    On Friday, July 28, 2023 at 11:31:02 AM UTC-4, Paul Edwards wrote:
    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. :(

    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....

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to All on Fri Jul 28 16:27:45 2023
    The same problem occurred with OW. :(

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Edwards@21:1/5 to Harry Potter on Sat Jul 29 23:59:43 2023
    On Saturday, July 29, 2023 at 7:08:52 AM UTC+8, Harry Potter wrote:

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

    The problem code:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to Paul Edwards on Sun Jul 30 03:05:33 2023
    On Sunday, July 30, 2023 at 2:59:45 AM UTC-4, Paul Edwards wrote:
    I asked you to put a return 0 after that puts. I don't see it.

    I plan to try that later today.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to All on Sun Jul 30 16:04:15 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Edwards@21:1/5 to Harry Potter on Sun Jul 30 17:01:01 2023
    On Monday, July 31, 2023 at 7:04:18 AM UTC+8, Harry Potter wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to Paul Edwards on Mon Jul 31 03:07:45 2023
    On Sunday, July 30, 2023 at 8:01:04 PM UTC-4, Paul Edwards wrote:
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Edwards@21:1/5 to Harry Potter on Mon Jul 31 18:43:19 2023
    On Monday, July 31, 2023 at 6:07:47 PM UTC+8, Harry Potter wrote:

    On Sunday, July 30, 2023 at 8:01:04 PM UTC-4, Paul Edwards wrote:
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to All on Thu Aug 3 14:24:07 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Edwards@21:1/5 to Harry Potter on Sun Aug 6 03:36:13 2023
    On Friday, August 4, 2023 at 5:24:09 AM UTC+8, Harry Potter wrote:
    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();

    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.

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard@21:1/5 to All on Tue Aug 8 15:26:51 2023
    [Please do not mail me a copy of your followup]

    Harry Potter <rose.joseph12@yahoo.com> spake the secret code <0ab85c17-29a8-4c80-90f7-d739afc6e4f6n@googlegroups.com> thusly:

    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>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to Richard on Wed Aug 9 16:39:13 2023
    On Tuesday, August 8, 2023 at 11:26:55 AM UTC-4, Richard wrote:
    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. :(

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harry Potter@21:1/5 to All on Sat Aug 12 06:06:55 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)