Skip to content

Added fix for enca to exit 1 each time it prints 'unknown' #19.#76

Merged
nijel merged 1 commit into
Project-OSS-Revival:masterfrom
Syed-Shahrukh-OSSRevival:t19
Jun 11, 2025
Merged

Added fix for enca to exit 1 each time it prints 'unknown' #19.#76
nijel merged 1 commit into
Project-OSS-Revival:masterfrom
Syed-Shahrukh-OSSRevival:t19

Conversation

@Syed-Shahrukh-OSSRevival

Copy link
Copy Markdown
Member
  • Updated the function return type which printed the unknown, so it return error in case of unknown.
  • Added cover for edge cases of error.

@nijel

nijel commented Jun 9, 2025

Copy link
Copy Markdown
Collaborator

Shouldn't the enca_charset_is_known logic be fixed instead?

@Syed-Shahrukh-OSSRevival

Copy link
Copy Markdown
Member Author

This is the implementation of enca_charset_is_known which checks if the charset is know or not. ENCA_CS_UNKNOWN = -1

enca.h:139

#define enca_charset_is_known(cs) \
  ((cs) != ENCA_CS_UNKNOWN)

With the -m flag the charset is searched within CHARSET_INFO array by the function enca_charset_name encnames.c:137

The data structure that is used by the array is defined in internal.h:77

struct _EncaCharsetInfo {
  int enca;
  int rfc1345;
  int cstocs;
  int iconv;
  int mime;
  const char *human;
  unsigned int flags;
  unsigned int nsurface;
};

encoding.h:3

EncaCharsetInfo CHARSET_INFO[] =

For the charset this is the array entry. The value of mime is -1.

  {
     148, 150, -1, 149, -1,
     "Macintosh Cyrillic",
     ENCA_CHARSET_8BIT | ENCA_CHARSET_FIXED | ENCA_CHARSET_REGULAR,
     ENCA_SURFACE_EOL_CR
  }

Using the array data function enca_charset_name
enca.c:279

 case OTYPE_MIME:
    if (enca_charset_name(result.charset, ENCA_NAME_STYLE_MIME) != NULL)
      puts(enca_charset_name(result.charset, ENCA_NAME_STYLE_MIME));
    else {
      puts(enca_charset_name(ENCA_CS_UNKNOWN, ENCA_NAME_STYLE_MIME));
      res = ERR_CANNOT;
    }

The function returns NULL at
encnames.c:181

    case ENCA_NAME_STYLE_MIME:
    return cs->mime < 0 ? NULL : ALIAS_LIST[cs->mime];

So the else case is executed

encnames.c:142

  if (charset == ENCA_CS_UNKNOWN) {
    switch (whatname) {
      case ENCA_NAME_STYLE_RFC1345:
      case ENCA_NAME_STYLE_ENCA:
      case ENCA_NAME_STYLE_MIME:
      return UNKNOWN_CHARSET_NAME;

which prints unknown.

So to ensure that this unknown is covered a return type is added to print_results. enca.c:215

@nijel
nijel merged commit dc3e9cd into Project-OSS-Revival:master Jun 11, 2025
1 of 4 checks passed
@nijel

nijel commented Jun 11, 2025

Copy link
Copy Markdown
Collaborator

Merged, thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants