Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A small bug and some warnings while compiling #1

Closed
g-berthiaume opened this issue Mar 7, 2022 · 2 comments
Closed

A small bug and some warnings while compiling #1

g-berthiaume opened this issue Mar 7, 2022 · 2 comments
Assignees

Comments

@g-berthiaume
Copy link

Hi,
here are some small comments about microrl.
I'm in the process of testing your lib with a test project because it seems like exactly what I need.


microrl is not compiling because size_t is not defined.
Simple fix: add #include <stdlib.h> to line 33.

In some of my projects, I'm required to compile with warning levels.
Here are some of my finding:

../App/Lib/microrl.c:166:44: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'unsigned int'} [-Wsign-compare]
  166 |                 if (!((str - mrl->cmdline) < limit)) {
      |                                            ^
../App/Lib/microrl.c:371:20: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'unsigned int'} and 'int32_t' {aka 'long int'} [-Wsign-compare]
  371 |         *j++ = ((i >= mrl->echo_off_pos) && (mrl->echo != MICRORL_ECHO_ON)) ? '*' : mrl->cmdline[i];
      |                    ^~
../App/Lib/microrl.c:372:23: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'unsigned int'} [-Wsign-compare]
  372 |         if ((j - str) == strlen(str)) {
      |                       ^~
../App/Lib/microrl.c:379:31: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
  379 |     if ((j - str + 3 + 6 + 1) > MICRORL_ARRAYSIZE(str)) {
      |                               ^
../App/Lib/microrl.c: In function 'microrl_processing_input':
../App/Lib/microrl.c:1017:46: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'unsigned int'} and 'int32_t' {aka 'long int'} [-Wsign-compare]
 1017 |                             if ((mrl->cursor >= mrl->echo_off_pos) && (mrl->echo != MICRORL_ECHO_ON)) {

If you want to reproduce, you can add the following in your makefile

CCFLAGS   = -Wall $(DEBUG) -Wextra -pedantic -std=gnu99 -I../src/include/microrl -I../examples -iquote unix_misc

Thanks for your work!
Very interesting and useful project.

@g-berthiaume g-berthiaume changed the title A small bug and some small warning while compiling A small bug and some small warnings while compiling Mar 7, 2022
@g-berthiaume g-berthiaume changed the title A small bug and some small warnings while compiling A small bug and some warnings while compiling Mar 7, 2022
@dimmykar
Copy link
Owner

dimmykar commented Mar 18, 2022

Hello, @g-berthiaume!
I'm so sorry for the long answer...
Many thanks for this catch. It is very corner case of my testing procedure, because on my Linux PC the Unix example compiled successfully.


I have added to microrl.h header the #include <stddef.h> with size_t type.
In the near future I will fix incorrect unsigned-signed types comparisons and release a corresponding patch.


If interested, you can also take look at my new microsh library based on microrl, it might be of interest to you too.

@dimmykar dimmykar self-assigned this Mar 18, 2022
@dimmykar
Copy link
Owner

I have fixed all warnings in develop branch

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

No branches or pull requests

2 participants