The Better String Library

Overview

The Better String Library

The Better String Library is an abstraction of a string data type which is superior to the C library char buffer string type, or C++'s std::string. Among the features achieved are:

  • Substantial mitigation of buffer overflow/overrun problems and other failures that result from erroneous usage of the common C string library functions

  • Significantly simplified string manipulation

  • High performance interoperability with other source/libraries which expect '\0' terminated char buffers

  • Improved overall performance of common string operations

  • Functional equivalency with other more modern languages

The library is totally stand alone, portable (known to work with gcc/g++, MSVC++, Intel C++, WATCOM C/C++, Turbo C, Borland C++, IBM's native CC compiler on Windows, Linux and Mac OS X), high performance, easy to use and is not part of some other collection of data structures. Even the file I/O functions are totally abstracted (so that other stream-like mechanisms, like sockets, can be used.) Nevertheless, it is adequate as a complete replacement of the C string library for string manipulation in any C program.

The library includes a robust C++ wrapper that uses overloaded operators, rich constructors, exceptions, stream I/O and STL to make the CBString struct a natural and powerful string abstraction with more functionality and higher performance than std::string.

Bstrlib is stable, well tested and suitable for any software production environment.

Issues
  • Removed compiler warnings [-Wself-assign] for a cleaner build output …

    Removed compiler warnings [-Wself-assign] for a cleaner build output …

    I added an UNDEFINED(X) macro in the single file that produces [-Wself-assign] warnings at build time.

    This removes the false sense of something being wrong; the sentiment in the code is clear and perfectly legitimate. However, some build processes take output as a sign of weakness or failure!

    opened by emacstheviking 2
  • Making it easier for ld to find this library

    Making it easier for ld to find this library

    Is it possible to rename bstrlib as libbstr? Or I should name the shared library as libbstrlib.so ? I am packaging bstrlib as a shared library on Fedora, a linux distribution. I named the shared library libbstr.so,so it can be found easily be ld, but this introduce some unnecessary confusion. I have added a pkg-config file as a workaround.

    opened by yceh 1
  • bstrlib doesn't really handle buffer overflow

    bstrlib doesn't really handle buffer overflow

    Many of the overflow checks in bstrlib use meaningless code that compilers are free to ignore, which they in fact do. Compare the size calculation loop at the beginning of bjoinblk compiled with gcc 4.9.2 with gcc -O2 -fno-strict-overflow:

    0x00003f48      498b04ce       mov rax, qword [r14 + rcx*8]
    0x00003f4c      8b4004         mov eax, dword [rax + 4]    ; [0x4:4]=0x10102 
    0x00003f4f      85c0           test eax, eax
    0x00003f51      0f8821010000   js 0x4078                  
    0x00003f57      4101c7         add r15d, eax
    0x00003f5a      0f8818010000   js 0x4078                  
    0x00003f60      4883c101       add rcx, 1
    0x00003f64      4139cd         cmp r13d, ecx
    0x00003f67      7fdf           jg 0x3f48
    

    and with plain gcc -O2:

    0x00004098      498b0cc6       mov rcx, qword [r14 + rax*8]
    0x0000409c      8b4904         mov ecx, dword [rcx + 4]    ; [0x4:4]=0x10102 
    0x0000409f      85c9           test ecx, ecx
    0x000040a1      0f8819010000   js 0x41c0                  
    0x000040a7      4883c001       add rax, 1
    0x000040ab      4101cf         add r15d, ecx
    0x000040ae      4139c5         cmp r13d, eax
    0x000040b1      7fe5           jg 0x4098                  
    

    and note the absence of the js instruction after the addition to r15d (corresponding to the overflow check if (c < 0) return NULL; /* Wrap around ?? */).

    The following functions are compiled differently in bstrlib.c with and without -fno-strict-overflow and may contain security vulnerabilities:

    buildCharField findreplaceengine ballocmin bassigncstr bassignblk brtrimws btrimws binstrr binstrrcaseless bstrrchrp binchr binchrr bninchr bninchrr breplace binsertch bpattern bassigngets bgetsa bsreadlna bsreadlnsa bsreada bjoinblk bssplitscb bstrListDestroy bsplitcb bsplitscb bvcformata

    Not all will be compiled to broken code, but I am moderately sure that at least the following are real bugs:

     gcc -c -O2 -Wstrict-overflow bstrlib.c -o b2n.o                                                                                            
    bstrlib.c: In function ‘findreplaceengine’:
    bstrlib.c:1780:22: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
       if (pos < 0 || acc < 0) {
                          ^
    bstrlib.c: In function ‘breplace’:
    bstrlib.c:1623:25: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
      if (pos < 0 || len < 0 || (pl = pos + len) < 0 || b1 == NULL ||
                             ^
    bstrlib.c: In function ‘bsreada’:
    bstrlib.c:2252:5: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
      if (n <= 0) return BSTR_ERR;
         ^
    bstrlib.c: In function ‘bjoinblk’:
    bstrlib.c:2391:6: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
       if (c < 0) return NULL; /* Wrap around ?? */
          ^
    bstrlib.c: In function ‘bvcformata’:
    bstrlib.c:3137:5: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
      if (n > BSTR_ERR-1) n = BSTR_ERR-1;
         ^
    
    opened by fhars 1
  • Modified __GNUC__ vsnprintf prototype declaration to exclude OSX

    Modified __GNUC__ vsnprintf prototype declaration to exclude OSX

    opened by ryanpdwyer 1
  • CBString::format causes access violation issues

    CBString::format causes access violation issues

    I wanted to use CBString::format() function in my logger implementation, but it causes access violation errors in my application (it's always in the same place, if I replace code with char[] everything works just fine).

    Similar code using c-strings works just fine:

    void log(const char* format, const char* arg1, const char* arg2)
    {
        char buffer[2048];
        sprintf_s((char*)&buffer, sizeof(buffer), format, arg1, arg2);
        logtofile(buffer);
    }
    

    Example with CBString::format:

    // this causes AV errors sometimes, don't know exactly why
    void logBStrLib(const char* format, const char* arg1, const char* arg2)
    {
        Bstrlib::CBString buffer;
        buffer.format(format, arg1, arg2);
        logtofile((const char*)buffer);
    }
    
    opened by bajoraitisd 0
  • References in text to bstrcat should be replaced with bconcat

    References in text to bstrcat should be replaced with bconcat

    I'm guessing it's just a name change that hasn't gone through everywhere?

    ack bstrcat leaves the following occurances:

    bstrlib/bsafe.c
    37:     fprintf (stderr, "bsafe error: strcat() is not safe, use bstrcat instead.\n");
    64:     fprintf (stderr, "bsafe error: strncat() is not safe, use bstrcat then btrunc\n\torcstr2tbstr, btrunc then bstrcat instead.\n");
    
    bstrlib/bstrlib.txt
    187:        bstrcat (p = bfromcstr ("Hello,"), q = bfromcstr (" World"));
    191:failure to allocate memory) both bstrcat and bdestroy will recognize it and
    

    It left me hanging when trying out one of the earliest code snippets in bstrlib.txt.

    Hugs

    opened by ghost 0
  • Signedness comparison issue

    Signedness comparison issue

    Hey guys, I'm currently getting this error:

    src/bstrlib/bstrlib.c: In function 'findreplaceengine': src/bstrlib/bstrlib.c:1754:13: error: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Werror=sign-compare] if (mlen > (INT_MAX / sizeof(int *)) / 2) {

    I cast mlen to unsigned and that works fine:

    if ((unsigned)mlen > (INT_MAX / sizeof(int *)) / 2) {

    But wondering what people think of this?

    I'm on Windows 10 using MinGW-W64 8.1.0 with -Wall -Wextra -pedantic -Werror.

    opened by Sidewinder1138 0
  • typedef struct bstrList * to a more user-friendly mnemonic

    typedef struct bstrList * to a more user-friendly mnemonic

    When you use usual bstrlib functions, it's pretty handy that they return a bstring instead of a struct tagbstring *.

    But I wonder why is this not done for struct bstrList *?

    Do you think such a change is reasonable? Should I submit a pull request?

    opened by preslavmihaylov 0
  • Fixed several broken links

    Fixed several broken links

    Hi Paul – Most of your links are broken – in many cases the websites as such don't even exist anymore. I found good replacement links for safestr, fireString, wxString, etc. (I couldn't find anything on "Str Library", which is probably a tough name to search.) Note that many of your comparisons are against libraries that were abandoned 14 or more years ago (e.g. fireString and libclc were abandoned in 2003). I for one would love to read updated comparisons with modern, active libraries – string handling is fundamentally important.

    opened by JoeUX 0
Releases(v1.0.0)
header-only UTF-8 string functions based on STL-string

utf8_xxx header-only UTF-8 string functions based on STL-string size_t utf8_len(const std::string& _Str) std::string utf8_sub(const std::string& _Str,

Voidmatrix 2 Dec 27, 2021
C Program to input a string and adjust memory allocation according to the length of the string.

C-String C Program to input a string and adjust memory allocation according to the length of the string. With the help of this program, we have replic

Kunal Kumar Sahoo 1 Jan 20, 2022
A better hexdump

huxdemp (aka hxd) huxdemp is an advanced version of the venerable hexdump that uses colors, bolding, and other terminal formatting to distinguish betw

LPTSTR 58 Jun 11, 2022
The Pizza Compass will determine your location and direct you to the nearest pizza place. It’s like a regular compass, but better!

Pizza_Compass A Particle project named Pizza_Compass Welcome to your project! Every new Particle project is composed of 3 important elements that you'

Joe Grand 66 Jul 25, 2022
Thread Stack Spoofing - PoC for an advanced In-Memory evasion technique allowing to better hide injected shellcode's memory allocation from scanners and analysts.

Thread Stack Spoofing PoC A PoC implementation for an advanced in-memory evasion technique that spoofs Thread Call Stack. This technique allows to byp

Mariusz B. 663 Jul 27, 2022
T-HYDRA is a modified version of original thc-hydra for better use inside Termux .

T-HYDRA is a modified version of original thc-hydra for better use inside Termux . Earlier , hydra pakage had been with Termux repositories. Then afte

Devil Master 34 Jul 24, 2022
Stock exchange simulator made in Swing using Java with logic backend in C++ giving it faster load time and better data control

StockSimulator Stock exchange simulator made in Swing using Java with logic backend in C++ giving it faster load time and better data control Features

Dušan Todorović 0 Mar 1, 2022
Visual-inertial-wheel fusion odometry, better performance in scenes with drastic changes in light

VIW-Fusion An visual-inertial-wheel fusion odometry VIW-Fusion is an optimization-based viusla-inertial-wheel fusion odometry, which is developed as a

庄庭达 189 Aug 6, 2022
Turn images into text better than caca/aalib

hiptext hiptext is command line tool for rendering images and videos inside terminals. Dependencies You need clang or gcc >=4.7. You also need to inst

Justine Tunney 664 Jul 29, 2022
Refinements of the WFA alignment algorithm with better complexity

wfalm Refinements of the WFA alignment algorithm with better complexity Introduction This repository contains implementations of the WFA algorithm as

Jordan Eizenga 23 Jun 11, 2022
Small Extremely Powerful Header Only C++ Lexical Analyzer/String Parser Library

lexpp Small Extremely Powerful Header Only C++ Lexical Analyzer/String Parser Library Lexpp is made with simplicity and size in mind. The entire libra

Jaysmito Mukherjee 49 Jun 21, 2022
Minimal freestanding C library for kernel dev. Think Rust's libcore but for C. (memutils, string formatting, etc)

Libcore Minimal freestanding C library. Features String formatting. Memory utils memcpy memmove memcmp String utils strlen strncpy strncmp Serial driv

Anthony 3 Oct 21, 2021
Header-only library providing unicode aware string support for C++

CsString Introduction CsString is a standalone library which provides unicode aware string support. The CsBasicString class is a templated class which

CopperSpice 91 Jul 14, 2022
A run-time C++ library for working with units of measurement and conversions between them and with string representations of units and measurements

Units What's new Some of the CMake target names have changed in the latest release, please update builds appropriately Documentation A library that pr

Lawrence Livermore National Laboratory 106 Jul 22, 2022
Pipet - c++ library for building lightweight processing pipeline at compile-time for string obfuscation, aes ciphering or whatever you want

Pipet Pipet is a lightweight c++17 headers-only library than can be used to build simple processing pipelines at compile time. Features Compile-time p

C. G. 59 Jul 30, 2022
(Simple String Format) is an syntax of format and a library for parse this.

SSFMT (Simple String Format) is an syntax of format and a library for parse this. SSFMT != {fmt} SSFMT is NOT an API/library for parse {fmt} syntax !

null 2 Jan 30, 2022
Solves a given NxN wordsearch in under 0.3 seconds at most using Rabin-Karp string algorithm.

ASSIGNMENT 2 The Information of the Creator: ASSIGNMENT 2 Author: Lukas Waschuk CCID: lwaschuk Date: 03-20-2021 The Purpose of Your Program: This prog

Lukas Waschuk 0 May 17, 2022
📚 single header utf8 string functions for C and C++

?? utf8.h A simple one header solution to supporting utf8 strings in C and C++. Functions provided from the C header string.h but with a utf8* prefix

Neil Henning 1.2k Jul 27, 2022