Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1066535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:01:53+00:00 2026-05-16T20:01:53+00:00

I’ve written a program called Mathtext . This program gives plain text style by

  • 0

I’ve written a program called Mathtext. This program gives plain text “style” by shifting certain character ranges into Unicode ranges such as ‘mathematical letterlike symbols” to produce plain-text italics, bold, serif, etc.

It works as a line-by-line interpreter, like a shell, outputting the translated line after a line is entered. This means that files can be cat/piped in to translate an entire file, as well as the fact that you can ‘exit’ the ‘shell’ by pressing ^D, which is detected by stdin hitting EOF.

Everything works. However, when I press ^D and exit, it segfaults. I still can’t quite grasp what is causing this.

Compiling with -g -O0 helps a little; I now know that the problem arises from a strlen call in transpose when ^D is pressed. However, transpose should never be called during ^D, as eof is true!

Program received signal SIGSEGV, Segmentation fault.
__strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:31
31    ../sysdeps/x86_64/multiarch/../strlen.S: No such file or directory.
    in ../sysdeps/x86_64/multiarch/../strlen.S
(gdb) where
#0  __strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:31
#1  0x0000000000400b0e in transpose (s=0x0, capsDelta=120263, smallDelta=120257, numDelta=0) at mathtext.c:58
#2  0x0000000000400e2b in main (argc=2, argv=0x7fffffffe4b8) at mathtext.c:92
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:01:54+00:00Added an answer on May 16, 2026 at 8:01 pm

    Most uses of feof() are a bug – and this program demonstrates it perfectly in this main loop:

    char temp[1048576];
    do {
        if (!strcmp(argv[1], "serifb"))
            transpose(fgets(temp, 1048576, stdin), 119808 - 'A', 119834 - 'a', 120782 - '0');
        else if (!strcmp(argv[1], "serifi"))
            transpose(fgets(temp, 1048576, stdin), 119860 - 'A', 119886 - 'a', 0);
        else if (!strcmp(argv[1], "serifbi"))
            transpose(fgets(temp, 1048576, stdin), 119912 - 'A', 119938 - 'a', 0);
        else if (!strcmp(argv[1], "sans"))
            transpose(fgets(temp, 1048576, stdin), 120224 - 'A', 120250 - 'a', 120802 - '0');
        else if (!strcmp(argv[1], "sansb"))
            transpose(fgets(temp, 1048576, stdin), 120276 - 'A', 120302 - 'a', 120812 - '0');
        else if (!strcmp(argv[1], "sansi"))
            transpose(fgets(temp, 1048576, stdin), 120328 - 'A', 120354 - 'a', 0);
        else if (!strcmp(argv[1], "sansbi"))
            transpose(fgets(temp, 1048576, stdin), 120380 - 'A', 120406 - 'a', 0);
        else if (!strcmp(argv[1], "mono"))
            transpose(fgets(temp, 1048576, stdin), 120432 - 'A', 120458 - 'a', 120822 - '0');
        else if (!strcmp(argv[1], "fullwidth"))
            transposeBlock(fgets(temp, 1048576, stdin), '!', '~', 65281 - '!');
        else return help();
    } while(!feof(stdin));
    

    At end-of-file, fgets() will return NULL, and then the next invocation of feof() will return true. So the correct approach is to test the return value of your input function – and since you’re doing that test anyway, there’s no need to call feof() (unless you want to distinguish a file error from end-of-file).

    char temp[1048576];
    while (fgets(temp, sizeof temp, stdin) != NULL) {
        if (!strcmp(argv[1], "serifb"))
            transpose(temp, 119808 - 'A', 119834 - 'a', 120782 - '0');
        else if (!strcmp(argv[1], "serifi"))
            transpose(temp, 119860 - 'A', 119886 - 'a', 0);
        else if (!strcmp(argv[1], "serifbi"))
            transpose(temp, 119912 - 'A', 119938 - 'a', 0);
        else if (!strcmp(argv[1], "sans"))
            transpose(temp, 120224 - 'A', 120250 - 'a', 120802 - '0');
        else if (!strcmp(argv[1], "sansb"))
            transpose(temp, 120276 - 'A', 120302 - 'a', 120812 - '0');
        else if (!strcmp(argv[1], "sansi"))
            transpose(temp, 120328 - 'A', 120354 - 'a', 0);
        else if (!strcmp(argv[1], "sansbi"))
            transpose(temp, 120380 - 'A', 120406 - 'a', 0);
        else if (!strcmp(argv[1], "mono"))
            transpose(temp, 120432 - 'A', 120458 - 'a', 120822 - '0');
        else if (!strcmp(argv[1], "fullwidth"))
            transposeBlock(temp, '!', '~', 65281 - '!');
        else return help();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.