Giter Club home page Giter Club logo

ultimate-string-library's Introduction

ultimate-string-library

The ultimate string library for C where it's purpose is to eliminate the use of null terminators but allow C stdlib interactivity

How to use

#include "usl.h"

int main() {
    usl str = usl_from("Hello, World!");
    usl str2 = usl_from("Hello, World!");
    usl str3 = usl_concat(str, str2);
    printf("%s\n", usl_as_str(str3));
    usl_free(str);
    usl_free(str2);
    usl_free(str3);
}

How to install

include(FetchContent)
FetchContent_Declare(usl
  URL https://github.com/mauro-balades/ultimate-string-library.git
)

FetchContent_MakeAvailable(usl)
target_link_libraries(${PROJECT_NAME} PRIVATE usl)

How does it work?

The library uses a tipical char* but it also stores the length of the string in the first 4 bytes of the pointer.

Why?

I wanted to make a string library that was easy to use and didn't require the use of null terminators. I also wanted to make it so that it was easy to convert to a char* so that it could be used with the C stdlib.

The C stdlib kinda... sucks when it comes to strings. It's not very safe and it's very easy to make mistakes. I wanted to make a library that was easy to use and didn't require the use of null terminators. I also wanted to make it so that it was easy to convert to a char* so that it could be used with the C stdlib.

here's an example of the string representation:

[4 bytes] [n bytes]
[length] [string]
"Hello"
[5 bytes] [5 bytes]
[0x05] [Hello]

        H E L L O
--------------
0 0 0 5 H E L L O

ultimate-string-library's People

Contributors

mauro-balades avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ultimate-string-library's Issues

Missing boundary check (overflow)

Hi,

saw your post in r/C_Programming, looks like a nice project :D

I browsed through your code and I think there is an issue with memory management due to missing boundary checks:

  • usl_new should check if size is less than the maximum 4 bytes (USL_SIZE)
  • usl_from should check if len is less than the maximum 4 bytes (USL_SIZE)
  • usl_concat should check if new_len is less than the maximum 4 bytes (USL_SIZE)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.