<commit_before>'use strict'
var util = require('./util')
var BN = require('ethereumjs-util').BN

function DynamicByteArray () {
  this.storageSlots = 1
  this.storageBytes = 32
  this.typeName = 'bytes'
}

DynamicByteArray.prototype.decodeFromStorage = function (location, storageContent) {
  var value = util.extractHexValue(location, storageContent, this.storageBytes)
  var bn = new BN(value, 16)
  if (bn.testn(0)) {
    var length = bn.div(new BN(2))
    var dataPos = new BN(util.sha3(location.slot).replace('0x', ''), 16)
    var ret = ''
    var currentSlot = util.readFromStorage(dataPos, storageContent)
    while (length.gt(ret.length) && ret.length < 32000) {
      currentSlot = currentSlot.replace('0x', '')
      ret += currentSlot
      dataPos = dataPos.add(new BN(1))
      currentSlot = util.readFromStorage(dataPos, storageContent)
    }
    return {
      value: '0x' + ret.replace(/(00)+$/, ''),
      length: '0x' + length.toString(16)
    }
  } else {
    var size = parseInt(value.substr(value.length - 2, 2), 16) / 2
    return {
      value: '0x' + value.substr(0, size * 2),
      length: '0x' + size.toString(16)
    }
  }
}

DynamicByteArray.prototype.decodeLocals = function (stackHeight, stack, memory) {
  if (stack.length - 1 < stackHeight) {
    return {
      value: '0x',
      length: '0x'
    }
  } else {
    var offset = stack[stack.length - 1 - stackHeight]
    offset = 2 * parseInt(offset, 16)
    var length = memory.substr(offset, 64)
    length = parseInt(length, 16)
    return {
      length: 2 * length,
      value: '0x' + memory.substr(offset + 64, 2 * length)
    }
  }
}

module.exports = DynamicByteArray<commit_msg>decodeFromMemory DynamicByteArray<commit_after>'use strict'
var util = require('./util')
var BN = require('ethereumjs-util').BN

function DynamicByteArray () {
  this.storageSlots = 1
  this.storageBytes = 32
  this.typeName = 'bytes'
}

DynamicByteArray.prototype.decodeFromStorage = function (location, storageContent) {
  var value = util.extractHexValue(location, storageContent, this.storageBytes)
  var bn = new BN(value, 16)
  if (bn.testn(0)) {
    var length = bn.div(new BN(2))
    var dataPos = new BN(util.sha3(location.slot).replace('0x', ''), 16)
    var ret = ''
    var currentSlot = util.readFromStorage(dataPos, storageContent)
    while (length.gt(ret.length) && ret.length < 32000) {
      currentSlot = currentSlot.replace('0x', '')
      ret += currentSlot
      dataPos = dataPos.add(new BN(1))
      currentSlot = util.readFromStorage(dataPos, storageContent)
    }
    return {
      value: '0x' + ret.replace(/(00)+$/, ''),
      length: '0x' + length.toString(16)
    }
  } else {
    var size = parseInt(value.substr(value.length - 2, 2), 16) / 2
    return {
      value: '0x' + value.substr(0, size * 2),
      length: '0x' + size.toString(16)
    }
  }
}

DynamicByteArray.prototype.decodeLocals = function (stackHeight, stack, memory) {
  if (stack.length - 1 < stackHeight) {
    return {
      value: '0x',
      length: '0x0'
    }
  } else {
    var offset = stack[stack.length - 1 - stackHeight]
    offset = 2 * parseInt(offset, 16)
    return this.decodeFromMemory(offset, memory)
  }
}

DynamicByteArray.prototype.decodeFromMemory = function (offset, memory) {
  var length = memory.substr(offset, 64)
  length = 2 * parseInt(length, 16)
  return {
    length: '0x' + length.toString(16),
    value: '0x' + memory.substr(offset + 64, length)
  }
}

module.exports = DynamicByteArray
{'fraction_non_alphanumeric': 0.14400229029487546, 'fraction_numerical': 0.03006012024048096, 'mean_word_length': 3.174432497013142, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3938740', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1171, 'n_words': 263}