Coder Social home page Coder Social logo

buffer's People

Contributors

diasbruno avatar hjanuschka avatar jwerle avatar marcomorain avatar stephenmathieson avatar tj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

buffer's Issues

gcc on ubuntu complains about `ssize_t`

adding #include <sys/types.h> fixes this:

src/buffer.h:64:1: error: unknown type name ‘ssize_t’
src/buffer.h:68:43: error: unknown type name ‘ssize_t’
src/buffer.h:70:1: error: unknown type name ‘ssize_t’
src/buffer.c:87:1: error: unknown type name ‘ssize_t’
src/buffer.c:197:42: error: unknown type name ‘ssize_t’
src/buffer.c:228:1: error: unknown type name ‘ssize_t’

GCC 5.3.1 Compiler warning: sign compare

compiler

$ gcc --version
gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

result

buffer.c: In function ‘buffer_slice’:
buffer.c:248:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (to < from) return NULL;
          ^
buffer.c:254:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (to > len) to = len;
          ^
buffer.c: In function ‘buffer_print’:
buffer.c:347:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (i = 0; i < len; ++i) {

Buffer Prepend Does not Copy Correctly

Hello all,
I have come across an issue where for what appears to be no good reason buffer_prepend doesn't work as expected. I used the test.c buffer_prepend test as a template:

    buffer_t *buf = buffer_new();
    buffer_append(buf, " World");
    buffer_prepend(buf, "Hello");
    printf("HW: %s\n", buf->data);

Which returns:

HW: Hello World

As expected, but the following:

    buffer_t *file = buffer_new();
    buffer_append(file, "layout.bk.html");
    buffer_prepend(file, "./example/");
    printf("BASED: %s\n", file->data);

returns:

BASED: ./example/layout.bk.h

Cutting off the "tml" on the end of the file path.

I have played with the memmove function call and the only way I could get it to be reasonable was to have it copy the length of the "needed" length and not the length of the string to prepend. This could cause a write into memory not allocated for that buffer, so that is right out.

Not sure where to go from here.
Thanks,
Adam.

buffer_t.alloc is redundant ?

I'm confused by the .alloc member of buffer_t – it seems to always point to the same memory as .data.

One reason to have separate pointers for data and allocated data would be if the buffer could be passed in some initial space to use. Maybe something like this:

char buf[BUFFER_DEFAULT_SIZE];
struct buffer_t buffer;
buffer_init(buf, BUFFER_DEFAULT_SIZE);

after which buffer.data would point to the memory at buf, but buffer.alloc would be null. After pushing more than BUFFER_DEFAULT_SIZE characters into the buffer I would expect a realloc, after which .data and .alloc would point at the same piece of heap memory.

This is not how the code works though – the buffer is always heap allocated.

Possbile solutions:

  • allow user to pass in a block if initial memory (that .alloc would not reference)
  • remove the .alloc member

/cc @tj

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.