<commit_before>#include <stdio.h>
#include <stdarg.h>
#include <low/_stdio.h>

int __low_snprintf (ReadWriteInfo *rw, const void *src, size_t len)
{
  int ret, maxbytes = 0;
  char *dst;
  const char *src0 = (const char *) src;

  if (len && rw->m_handle)
    {
      maxbytes = MIN ((rw->m_limit - rw->m_size)-1, len);
      ret = maxbytes;
      dst = (char*)(rw->m_handle + rw->m_size);
      while (maxbytes)
      {
        *dst++ = *src0++;
        --maxbytes;
      }
      //memcpy (rw->m_handle + rw->m_size, src, maxbytes);
      rw->m_size += ret;
    }

  return len;
}

/* This custom snprintf does not use any floating point calculations,
   and can only format integer numbers. */
int snprintf (char *str, size_t size, const char *fmt, ...)
{
    int ret;
    ReadWriteInfo rw;
    va_list ap;
    va_start(ap, fmt);
    rw.m_handle = str;
    rw.m_fnptr = __low_snprintf;
    rw.m_size = 0;
    rw.m_limit = size;
    ret = _format_parser_int(&rw, fmt, &ap);
    va_end(ap);

    /* terminate the string */
    if (rw.m_handle)
      *((char *)rw.m_handle) = '\0';
    return ret;
}<commit_msg>Fixed obviously broken sprintf implementation imported from a bugged sniprintf<commit_after>#include <stdio.h>
#include <stdarg.h>
#include <low/_stdio.h>

int __low_snprintf (ReadWriteInfo *rw, const void *src, size_t len)
{
  int ret, maxbytes = 0;
  char *dst;
  const char *src0 = (const char *) src;

  if (len && rw->m_handle)
    {
      maxbytes = MIN ((rw->m_limit - rw->m_size)-1, len);
      ret = maxbytes;
      dst = (char*)(rw->m_handle + rw->m_size);
      while (maxbytes)
      {
        *dst++ = *src0++;
        --maxbytes;
      }
      //memcpy (rw->m_handle + rw->m_size, src, maxbytes);
      rw->m_size += ret;
    }

  return len;
}

/* This custom snprintf does not use any floating point calculations,
   and can only format integer numbers. */
int snprintf (char *str, size_t size, const char *fmt, ...)
{
    int ret;
    ReadWriteInfo rw;
    va_list ap;
    va_start(ap, fmt);
    rw.m_handle = str;
    rw.m_fnptr = __low_snprintf;
    rw.m_size = 0;
    rw.m_limit = size;
    ret = _format_parser_int(&rw, fmt, &ap);
    va_end(ap);

    /* terminate the string */
    if (rw.m_handle)
      *((char *)rw.m_handle + rw.m_size) = '\0';
    return ret;
}
{'fraction_non_alphanumeric': 0.1497605572485851, 'fraction_numerical': 0.00522420548541576, 'mean_word_length': 2.5083969465648854, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1652700', 'n_tokens_mistral': 888, 'n_tokens_neox': 856, 'n_words': 230}