bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Portable menu and forms libraries


From: Thomas Dickey
Subject: Re: Portable menu and forms libraries
Date: Fri, 26 Jul 2024 16:36:43 -0400

On Fri, Jul 26, 2024 at 12:18:51PM -0400, Bill Gray wrote:
> Follow-up re :
> 
> On 7/25/24 22:16, Bill Gray wrote:
> > (I did have to use 32-bit chtypes;  the default PDCursesMod 64-bit
> > chtypes got their upper half stripped,  resulting in default-color
> > menus.  Haven't puzzled that one out yet...)
> 
>    Turns out to be simple enough : menu/m_post.c has many calls to
> wattron()/wattroff() that cast the second parameter to int.  This, despite
> the parameter in question being a chtype,  so it's getting cast to int and
> back to chtype.  If chtype is larger than an int,  upper bits are lost.
> (I'm surprised I didn't get a warning about that,  despite using -Wall
> -Wextra -pedantic -Werror.)

But the prototype (X/Open) uses "int", and this causes warnings in the
stricter builds:

compiling m_post (obj_s)
../menu/m_post.c: In function ‘_nc_Post_Item’:
../menu/m_post.c:70:26: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
   70 |   wattron(menu->win, menu->back);
      |                      ~~~~^~~~~~
../menu/m_post.c:82:38: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
   82 |               wattron(menu->win, menu->fore);
      |                                  ~~~~^~~~~~
../menu/m_post.c:88:38: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
   88 |               wattron(menu->win, menu->fore);
      |                                  ~~~~^~~~~~
../menu/m_post.c:96:27: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
   96 |   wattroff(menu->win, menu->back);
      |                       ~~~~^~~~~~
../menu/m_post.c:104:30: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  104 |       wattron(menu->win, menu->grey);
      |                          ~~~~^~~~~~
../menu/m_post.c:111:34: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  111 |           wattron(menu->win, menu->fore);
      |                              ~~~~^~~~~~
../menu/m_post.c:116:34: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  116 |           wattron(menu->win, menu->back);
      |                              ~~~~^~~~~~
../menu/m_post.c:162:37: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  162 |             wattroff(menu->win, menu->grey);
      |                                 ~~~~^~~~~~
../menu/m_post.c:164:37: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  164 |             wattroff(menu->win, menu->fore);
      |                                 ~~~~^~~~~~
../menu/m_post.c:165:34: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  165 |           wattron(menu->win, menu->back);
      |                              ~~~~^~~~~~
../menu/m_post.c:179:37: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  179 |             wattroff(menu->win, menu->back);
      |                                 ~~~~^~~~~~
../menu/m_post.c:185:29: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  185 |     wattroff(menu->win, menu->fore);
      |                         ~~~~^~~~~~
../menu/m_post.c:187:29: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  187 |     wattroff(menu->win, menu->back);
      |                         ~~~~^~~~~~
../menu/m_post.c:189:29: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  189 |     wattroff(menu->win, menu->grey);
      |                         ~~~~^~~~~~
../menu/m_post.c: In function ‘_nc_Draw_Menu’:
../menu/m_post.c:234:38: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  234 |               wattron(menu->win, menu->back);
      |                                  ~~~~^~~~~~
../menu/m_post.c:253:35: warning: conversion to ‘int’ from ‘chtype’ {aka 
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
  253 |           wattroff(menu->win, menu->back);
      |                               ~~~~^~~~~~

>    The attached patch fixes the problem (basically,  removes "(int)" over
> and over and over from m_post.c.)
> 
>    I think with this fix,  plus the 'StdScreen' one-line fix mentioned in my
> previous e-mail,  the menu library can be considered portable to other
> curses implementations without further modifications.
> 
> -- Bill

> --- /tmp/m_post.c     2022-09-24 05:38:44.000000000 -0400
> +++ m_post.c  2024-07-26 12:06:06.516080752 -0400
> @@ -70 +70 @@
> -  wattron(menu->win, (int)menu->back);
> +  wattron(menu->win, menu->back);
> @@ -82 +82 @@
> -           wattron(menu->win, (int)menu->fore);
> +           wattron(menu->win, menu->fore);
> @@ -88 +88 @@
> -           wattron(menu->win, (int)menu->fore);
> +           wattron(menu->win, menu->fore);
> @@ -96 +96 @@
> -  wattroff(menu->win, (int)menu->back);
> +  wattroff(menu->win, menu->back);
> @@ -104 +104 @@
> -      wattron(menu->win, (int)menu->grey);
> +      wattron(menu->win, menu->grey);
> @@ -111 +111 @@
> -       wattron(menu->win, (int)menu->fore);
> +       wattron(menu->win, menu->fore);
> @@ -116 +116 @@
> -       wattron(menu->win, (int)menu->back);
> +       wattron(menu->win, menu->back);
> @@ -162 +162 @@
> -         wattroff(menu->win, (int)menu->grey);
> +         wattroff(menu->win, menu->grey);
> @@ -164,2 +164,2 @@
> -         wattroff(menu->win, (int)menu->fore);
> -       wattron(menu->win, (int)menu->back);
> +         wattroff(menu->win, menu->fore);
> +       wattron(menu->win, menu->back);
> @@ -179 +179 @@
> -         wattroff(menu->win, (int)menu->back);
> +         wattroff(menu->win, menu->back);
> @@ -185 +185 @@
> -    wattroff(menu->win, (int)menu->fore);
> +    wattroff(menu->win, menu->fore);
> @@ -187 +187 @@
> -    wattroff(menu->win, (int)menu->back);
> +    wattroff(menu->win, menu->back);
> @@ -189 +189 @@
> -    wattroff(menu->win, (int)menu->grey);
> +    wattroff(menu->win, menu->grey);
> @@ -234 +234 @@
> -           wattron(menu->win, (int)menu->back);
> +           wattron(menu->win, menu->back);
> @@ -253 +253 @@
> -       wattroff(menu->win, (int)menu->back);
> +       wattroff(menu->win, menu->back);


-- 
Thomas E. Dickey <dickey@invisible-island.net>
https://invisible-island.net

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]