ronantakizawa/codereview-bench huggingface dataset:
Repository: ossrs/srs
File: trunk/src/app/srs_app_srt_source.cpp (C++)

Code before:
            }

            hevc_vps_ = vps;
            continue;
        }

        // for sps
        if (hevc->is_sps(frame, frame_size)) {
            std::string sps;
            if ((err = hevc->sps_demux(frame, frame_size, sps)) != srs_success) {
                return srs_error_wrap(err, "demux sps");
            }

            if (! sps.empty() && hevc_sps_ != sps) {
                vps_sps_pps_change_ = true;
            }

            hevc_sps_ = sps;
            continue;
        }

        // for pps
        if (hevc->is_pps(frame, frame_size)) {
            std::string pps;
            if ((err = hevc->pps_demux(frame, frame_size, pps)) != srs_success) {
                return srs_error_wrap(err, "demux pps");
            }
            if (! pps.empty()) {
                vps_sps_pps_change_ = true;
            }
            hevc_pps_tmp.push_back(pps);
            continue;
        }

        ipb_frames.push_back(make_pair(frame, frame_size));
    }

    if (!hevc_pps_tmp.empty())
    {
        hevc_pps_.clear();
        hevc_pps_ = hevc_pps_tmp;
    }
    if ((err = check_vps_sps_pps_change(msg)) != srs_success) {
        return srs_error_wrap(err, "check vps sps pps");
    }

    return on_hevc_frame(msg, ipb_frames);
}

srs_error_t SrsSrtFrameBuilder::check_vps_sps_pps_change(SrsTsMessage* msg)
{

Review comment (suggestion):
May change the declcare of function from
`pps_demux(char *frame, int nb_frame, std::string &pps)`
to 
`pps_demux(char *frame, int nb_frame, std::vector<std::string>& pps_vec)`

And all of the code call this function should have correct behaviours.

Code after:
            }

            hevc_vps_ = vps;
            continue;
        }

        // for sps
        if (hevc->is_sps(frame, frame_size)) {
            std::string sps;
            if ((err = hevc->sps_demux(frame, frame_size, sps)) != srs_success) {
                return srs_error_wrap(err, "demux sps");
            }

            if (! sps.empty() && hevc_sps_ != sps) {
                vps_sps_pps_change_ = true;
            }

            hevc_sps_ = sps;
            continue;
        }

        // for pps
        if (hevc->is_pps(frame, frame_size)) {
            std::string pps;
            if ((err = hevc->pps_demux(frame, frame_size, pps)) != srs_success) {
                return srs_error_wrap(err, "demux pps");
            }

            if (!pps.empty()) {
                vps_sps_pps_change_ = true;
            }

            hevc_pps.push_back(pps);
            continue;
        }

        ipb_frames.push_back(make_pair(frame, frame_size));
    }

    if (!hevc_pps.empty()) {
        hevc_pps_ = hevc_pps;
    }

    if ((err = check_vps_sps_pps_change(msg)) != srs_success) {
        return srs_error_wrap(err, "check vps sps pps");
    }

    return on_hevc_frame(msg, ipb_frames);
}

srs_error_t SrsSrtFrameBuilder::check_vps_sps_pps_change(SrsTsMessage* msg)
Repository: ossrs/srs
File: trunk/src/app/srs_app_server.cpp (C++)

Code before:
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_app_rtmp_conn.hpp>
#include <srs_app_config.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_app_http_api.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_app_ingest.hpp>
#include <srs_app_source.hpp>
#include <srs_app_utility.hpp>
#include <srs_app_heartbeat.hpp>
#include <srs_app_mpegts_udp.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_caster_flv.hpp>
#include <srs_kernel_consts.hpp>
#include <srs_app_coworkers.hpp>
#include <srs_protocol_log.hpp>
#include <srs_app_latest_version.hpp>
#include <srs_app_conn.hpp>
#ifdef SRS_RTC
#include <srs_app_rtc_network.hpp>
#endif
#ifdef SRS_GB28181
#include <srs_app_gb28181.hpp>
#endif
#include <srs_app_rtc_server.hpp>

SrsSignalManager* SrsSignalManager::instance = NULL;

SrsSignalManager::SrsSignalManager(SrsServer* s)
{
    SrsSignalManager::instance = this;
    
    server = s;
    sig_pipe[0] = sig_pipe[1] = -1;
    trd = new SrsSTCoroutine("signal", this, _srs_context->get_id());
    signal_read_stfd = NULL;
}

SrsSignalManager::~SrsSignalManager()
{
    srs_freep(trd);

    srs_close_stfd(signal_read_stfd);
    
    if (sig_pipe[0] > 0) {
        ::close(sig_pipe[0]);
    }
    if (sig_pipe[1] > 0) {
        ::close(sig_pipe[1]);
    }

Review comment (suggestion):
Maybe add conditional compile here: `#ifdef SRS_RTC`, or consider move the `extern SrsResourceManager _srs_rtc_manager;` declaration and initialization to `srs_app_rtc_network.hpp|cpp`.

Code after:
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_app_rtmp_conn.hpp>
#include <srs_app_config.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_app_http_api.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_app_ingest.hpp>
#include <srs_app_source.hpp>
#include <srs_app_utility.hpp>
#include <srs_app_heartbeat.hpp>
#include <srs_app_mpegts_udp.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_caster_flv.hpp>
#include <srs_kernel_consts.hpp>
#include <srs_app_coworkers.hpp>
#include <srs_protocol_log.hpp>
#include <srs_app_latest_version.hpp>
#include <srs_app_conn.hpp>
#ifdef SRS_RTC
#include <srs_app_rtc_network.hpp>
#include <srs_app_rtc_server.hpp>
#endif
#ifdef SRS_GB28181
#include <srs_app_gb28181.hpp>
#endif

SrsSignalManager* SrsSignalManager::instance = NULL;

SrsSignalManager::SrsSignalManager(SrsServer* s)
{
    SrsSignalManager::instance = this;
    
    server = s;
    sig_pipe[0] = sig_pipe[1] = -1;
    trd = new SrsSTCoroutine("signal", this, _srs_context->get_id());
    signal_read_stfd = NULL;
}

SrsSignalManager::~SrsSignalManager()
{
    srs_freep(trd);

    srs_close_stfd(signal_read_stfd);
    
    if (sig_pipe[0] > 0) {
        ::close(sig_pipe[0]);
    }
    if (sig_pipe[1] > 0) {
        ::close(sig_pipe[1]);
    }
Repository: ossrs/srs
File: trunk/3rdparty/st-srs/stk.c (C)

Code before:
    int mmap_flags = MAP_PRIVATE;
    void *vaddr;
    
#if defined (MD_USE_SYSV_ANON_MMAP)
    if (zero_fd < 0) {
        if ((zero_fd = open("/dev/zero", O_RDWR, 0)) < 0)
            return NULL;
        fcntl(zero_fd, F_SETFD, FD_CLOEXEC);
    }
#elif defined (MD_USE_BSD_ANON_MMAP)
    mmap_flags |= MAP_ANON;
#else
#error Unknown OS
#endif
    
    vaddr = mmap(NULL, size, PROT_READ | PROT_WRITE, mmap_flags, zero_fd, 0);
    if (vaddr == (void *)MAP_FAILED)
        return NULL;
    
#endif /* MALLOC_STACK */
    
    return (char *)vaddr;
}


/* Not used */
void _st_delete_stk_segment(char *vaddr, int size)
{
#ifdef MALLOC_STACK
    free(vaddr);
#else
    (void) munmap(vaddr, size);
#endif
}

int st_randomize_stacks(int on)
{
    int wason = _st_randomize_stacks;
    
    _st_randomize_stacks = on;
    if (on)
        srandom((unsigned int) st_utime());
    
    return wason;
}


Review comment (performance):
1. remove the no longer correct `/* Not used */` comment.
2. `_st_delete_stk_segment` only used when `#ifndef MD_CACHE_STACK`, but when `#ifdef MD_CACHE_STACK`, is the stk segment released? or where to call `_st_delete_stk_segment`?


Code after:
    int mmap_flags = MAP_PRIVATE;
    void *vaddr;
    
#if defined (MD_USE_SYSV_ANON_MMAP)
    if (zero_fd < 0) {
        if ((zero_fd = open("/dev/zero", O_RDWR, 0)) < 0)
            return NULL;
        fcntl(zero_fd, F_SETFD, FD_CLOEXEC);
    }
#elif defined (MD_USE_BSD_ANON_MMAP)
    mmap_flags |= MAP_ANON;
#else
#error Unknown OS
#endif
    
    vaddr = mmap(NULL, size, PROT_READ | PROT_WRITE, mmap_flags, zero_fd, 0);
    if (vaddr == (void *)MAP_FAILED)
        return NULL;
    
#endif /* MALLOC_STACK */
    
    return (char *)vaddr;
}


void _st_delete_stk_segment(char *vaddr, int size)
{
#ifdef MALLOC_STACK
    free(vaddr);
#else
    (void) munmap(vaddr, size);
#endif
}

int st_randomize_stacks(int on)
{
    int wason = _st_randomize_stacks;
    
    _st_randomize_stacks = on;
    if (on)
        srandom((unsigned int) st_utime());
    
    return wason;
}
Repository: ossrs/srs
File: trunk/src/app/srs_app_http_stream.cpp (C++)

Code before:

srs_error_t SrsBufferWriter::write(void* buf, size_t count, ssize_t* pnwrite)
{
    if (pnwrite) {
        *pnwrite = count;
    }
    return writer->write((char*)buf, (int)count);
}

srs_error_t SrsBufferWriter::writev(const iovec* iov, int iovcnt, ssize_t* pnwrite)
{
    return writer->writev(iov, iovcnt, pnwrite);
}

SrsLiveStream::SrsLiveStream(SrsRequest* r, SrsBufferCache* c)
{
    cache = c;
    req = r->copy()->as_http();
    security_ = new SrsSecurity();
}

SrsLiveStream::~SrsLiveStream()
{
    srs_freep(req);
    srs_freep(security_);
    viewers_.clear();
}

srs_error_t SrsLiveStream::update_auth(SrsRequest* r)
{
    srs_freep(req);
    req = r->copy()->as_http();
    
    return srs_success;
}

srs_error_t SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
    srs_error_t err = srs_success;

    SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
    SrsHttpConn* hc = dynamic_cast<SrsHttpConn*>(hr->connection());
    SrsHttpxConn* hxc = dynamic_cast<SrsHttpxConn*>(hc->handler());

    // Note that we should enable stat for HTTP streaming client, because each HTTP streaming connection is a real
    // session that should have statistics for itself.
    hxc->set_enable_stat(true);

    // Correct the app and stream by path, which is created from template.
    // @remark Be careful that the stream has extension now, might cause identify fail.
    req->stream = srs_path_basename(r->path());

Review comment (suggestion):
viewers need to be empty here, otherwise the loop in `do_serve_http` will break, and `server_http` will continue run. 

So add `srs_assert(viewers_.size() == 0);`, before `viewers.clear()`.

Code after:

srs_error_t SrsBufferWriter::write(void* buf, size_t count, ssize_t* pnwrite)
{
    if (pnwrite) {
        *pnwrite = count;
    }
    return writer->write((char*)buf, (int)count);
}

srs_error_t SrsBufferWriter::writev(const iovec* iov, int iovcnt, ssize_t* pnwrite)
{
    return writer->writev(iov, iovcnt, pnwrite);
}

SrsLiveStream::SrsLiveStream(SrsRequest* r, SrsBufferCache* c)
{
    cache = c;
    req = r->copy()->as_http();
    security_ = new SrsSecurity();
}

SrsLiveStream::~SrsLiveStream()
{
    srs_freep(req);
    srs_freep(security_);

    // The live stream should never be destroyed when it's serving any viewers.
    srs_assert(viewers_.empty());
}

srs_error_t SrsLiveStream::update_auth(SrsRequest* r)
{
    srs_freep(req);
    req = r->copy()->as_http();
    
    return srs_success;
}

srs_error_t SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
    srs_error_t err = srs_success;

    SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
    SrsHttpConn* hc = dynamic_cast<SrsHttpConn*>(hr->connection());
    SrsHttpxConn* hxc = dynamic_cast<SrsHttpxConn*>(hc->handler());

    // Note that we should enable stat for HTTP streaming client, because each HTTP streaming connection is a real
    // session that should have statistics for itself.
    hxc->set_enable_stat(true);

    // Correct the app and stream by path, which is created from template.
Repository: pcottle/learnGitBranching
File: src/js/stores/LocaleStore.js (JavaScript)

Code before:

var ActionTypes = AppConstants.ActionTypes;
var DEFAULT_LOCALE = 'en_US';

// resolve the messy mapping between browser language
// and our supported locales
var langLocaleMap = {
  en: 'en_US',
  zh: 'zh_CN',
  ja: 'ja',
  ko: 'ko',
  es: 'es_AR',
  fr: 'fr_FR',
  de: 'de_DE',
  pt: 'pt_BR',
  ru: 'ru_RU',
  uk: 'uk'
};

var headerLocaleMap = {
  'zh-CN': 'zh_CN',
  'zh-TW': 'zh_TW',
  'pt-BR': 'pt_BR'
};

var supportedLocalesList = _.values(langLocaleMap).concat(_.values(headerLocaleMap));

function _getLocaleFromHeader(langString) {
  var languages = langString.split(',');
  var desiredLocale;
  for (var i = 0; i < languages.length; i++) {
    var header = languages[i].split(';')[0];
    // first check the full string raw
    if (headerLocaleMap[header]) {
      desiredLocale = headerLocaleMap[header];
      break;
    }

    var lang = header.slice(0, 2);
    if (langLocaleMap[lang]) {
      desiredLocale = langLocaleMap[lang];
      break;
    }
  }
  return desiredLocale;
}

var _locale = DEFAULT_LOCALE;
var LocaleStore = assign(
{},
EventEmitter.prototype,

Review comment (refactor):
there are some duplicates here -- for instance `zh_CN` -- if we just add the values of each. can you convert to a set? or perhaps just make them all keys in an object?

also we dont need the underscore here since i polyfill

```
var allLocales = {};
Object.values(langLocaleMap).concat(Object.values(headerLocaleMap)).map(locale => allLocales[locale] = true);

// later
return Object.keys(allLocales)
```

Code after:
var ActionTypes = AppConstants.ActionTypes;
var DEFAULT_LOCALE = 'en_US';

// resolve the messy mapping between browser language
// and our supported locales
var langLocaleMap = {
  en: 'en_US',
  zh: 'zh_CN',
  ja: 'ja',
  ko: 'ko',
  es: 'es_AR',
  fr: 'fr_FR',
  de: 'de_DE',
  pt: 'pt_BR',
  ru: 'ru_RU',
  uk: 'uk'
};

var headerLocaleMap = {
  'zh-CN': 'zh_CN',
  'zh-TW': 'zh_TW',
  'pt-BR': 'pt_BR'
};

var supportedLocalesList = Object.values(langLocaleMap)
                                 .concat(Object.values(headerLocaleMap))
                                 .filter(function (value, index, self) { return self.indexOf(value) === index;});

function _getLocaleFromHeader(langString) {
  var languages = langString.split(',');
  var desiredLocale;
  for (var i = 0; i < languages.length; i++) {
    var header = languages[i].split(';')[0];
    // first check the full string raw
    if (headerLocaleMap[header]) {
      desiredLocale = headerLocaleMap[header];
      break;
    }

    var lang = header.slice(0, 2);
    if (langLocaleMap[lang]) {
      desiredLocale = langLocaleMap[lang];
      break;
    }
  }
  return desiredLocale;
}

var _locale = DEFAULT_LOCALE;
var LocaleStore = assign(
{},
Repository: pcottle/learnGitBranching
File: src/js/dialogs/confirmShowSolution.js (JavaScript)

Code before:
  }],
  'zh_CN': [{
    type: 'ModalAlert',
    options: {
      markdowns: [
        '## 确定要看答案吗？',
        '',
        '相信自己，你可以的！'
      ]
    }
  }],
  'zh_TW': [{
    type: 'ModalAlert',
    options: {
      markdowns: [
        '## 確定偷看解答嗎？',
        '',
        '我相信你！你可以的'
      ]
    }
  }],
  'es_AR': [{
    type: 'ModalAlert',
    options: {
      markdowns: [
        '## ¿Realmente quieres ver la solución?',
        '',
        '¡Creo en vos! ¡Dale que podés!'
      ]
    }
  }],
  'es_MX': [{
    type: 'ModalAlert',
    options: {
      markdowns: [
        '## ¿Estás seguro de que quieres ver la solución?',
        '',
        '¡Creo en ti! ¡Yo sé que puedes!'
      ]
    }
  }],
  'es_ES': [{
    type: 'ModalAlert',
    options: {
      markdowns: [
        '## ¿Estás seguro de que quieres ver la solución?',
        '',
        '¡Creo en ti! ¡Ánimo!'
      ]
    }
  }],

Review comment (suggestion):
```suggestion
        '## ¿Realmente querés ver la solución?',
```


Code after:
  }],
  'zh_CN': [{
    type: 'ModalAlert',
    options: {
      markdowns: [
        '## 确定要看答案吗？',
        '',
        '相信自己，你可以的！'
      ]
    }
  }],
  'zh_TW': [{
    type: 'ModalAlert',
    options: {
      markdowns: [
        '## 確定偷看解答嗎？',
        '',
        '我相信你！你可以的'
      ]
    }
  }],
  'es_AR': [{
    type: 'ModalAlert',
    options: {
      markdowns: [
        '## ¿Realmente querés ver la solución?',
        '',
        '¡Creo en vos! ¡Dale que podés!'
      ]
    }
  }],
  'es_MX': [{
    type: 'ModalAlert',
    options: {
      markdowns: [
        '## ¿Estás seguro de que quieres ver la solución?',
        '',
        '¡Creo en ti! ¡Yo sé que puedes!'
      ]
    }
  }],
  'es_ES': [{
    type: 'ModalAlert',
    options: {
      markdowns: [
        '## ¿Estás seguro de que quieres ver la solución?',
        '',
        '¡Creo en ti! ¡Ánimo!'
      ]
    }
  }],
Repository: pcottle/learnGitBranching
File: src/js/git/commands.js (JavaScript)

Code before:

      engine.reset(generalArgs[0]);
    }
  },

  revert: {
    regex: /^git +revert($|\s)/,
    execute: function(engine, command) {
      var generalArgs = command.getGeneralArgs();

      command.validateArgBounds(generalArgs, 1, Number.MAX_VALUE);
      engine.revert(generalArgs);
    }
  },

  merge: {
    regex: /^git +merge($|\s)/,
    options: [
      '--no-ff',
      '--squash'
    ],
    execute: function(engine, command) {
      var commandOptions = command.getOptionsMap();
      var generalArgs = command.getGeneralArgs().concat(commandOptions['--no-ff'] || []);
      command.validateArgBounds(generalArgs, 1, 1);

      var newCommit = engine.merge(
        generalArgs[0],
        {
          noFF: !!commandOptions['--no-ff'],
          squash: !!commandOptions['--squash']
        }
      );

      if (newCommit === undefined) {
        // its just a fast forward
        engine.animationFactory.refreshTree(
          engine.animationQueue, engine.gitVisuals
        );
        return;
      }

      engine.animationFactory.genCommitBirthAnimation(
        engine.animationQueue, newCommit, engine.gitVisuals
      );
    }
  },

  revlist: {
    dontCountForGolf: true,
    displayName: 'rev-list',

Review comment (suggestion):
so the command parsing is a little weird. itll grab the first argument *after* the `--no-ff` and put it into this options map.

but for boolean flags that doesnt make sense, so we tack them on manually. so i would do

command.getGeneralArgs().concat(commandOptions['--no-ff'] || []).concat(commandOptions['--squash'] || [])

and then it might work

Code after:

      engine.reset(generalArgs[0]);
    }
  },

  revert: {
    regex: /^git +revert($|\s)/,
    execute: function(engine, command) {
      var generalArgs = command.getGeneralArgs();

      command.validateArgBounds(generalArgs, 1, Number.MAX_VALUE);
      engine.revert(generalArgs);
    }
  },

  merge: {
    regex: /^git +merge($|\s)/,
    options: [
      '--no-ff',
      '--squash'
    ],
    execute: function(engine, command) {
      var commandOptions = command.getOptionsMap();
      var generalArgs = command.getGeneralArgs().concat(commandOptions['--no-ff'] || []).concat(commandOptions['--squash'] || []);
      command.validateArgBounds(generalArgs, 1, 1);

      var newCommit = engine.merge(
        generalArgs[0],
        {
          noFF: !!commandOptions['--no-ff'],
          squash: !!commandOptions['--squash']
        }
      );

      if (newCommit === undefined) {
        // its just a fast forward
        engine.animationFactory.refreshTree(
          engine.animationQueue, engine.gitVisuals
        );
        return;
      }

      engine.animationFactory.genCommitBirthAnimation(
        engine.animationQueue, newCommit, engine.gitVisuals
      );
    }
  },

  revlist: {
    dontCountForGolf: true,
    displayName: 'rev-list',
Repository: projectdiscovery/katana
File: pkg/output/output.go (Go)

Code before:
			return true
		}
	}

	return evalDslExpr(event, w.outputMatchCondition)
}

// filterOutput returns true if the event should be filtered out
func (w *StandardWriter) filterOutput(event *Result) bool {
	if w.filterRegex == nil && w.outputFilterCondition == "" {
		return false
	}
	for _, regex := range w.filterRegex {
		if regex.MatchString(event.Request.URL) {
			return true
		}
	}

	return evalDslExpr(event, w.outputFilterCondition)
}

func evalDslExpr(result *Result, dslExpr string) bool {
	resultMap, err := resultToMap(*result)
	if err != nil {
		gologger.Warning().Msgf("Could not map result: %s\n", err)
		return false
	}

	res, err := dsl.EvalExpr(dslExpr, resultMap)
	if err != nil {
		gologger.Error().Msgf("Could not evaluate DSL expression: %s\n", err)
		return false
	}
	return res == true
}

func resultToMap(result Result) (map[string]interface{}, error) {
	resultMap := make(map[string]any)
	config := &mapstructure.DecoderConfig{
		TagName: "json",
		Result:  &resultMap,
	}
	decoder, err := mapstructure.NewDecoder(config)
	if err != nil {
		return nil, fmt.Errorf("error creating decoder: %v", err)
	}
	err = decoder.Decode(result)
	if err != nil {
		return nil, fmt.Errorf("error decoding: %v", err)
	}
	return flatten(resultMap), nil

Review comment (suggestion):
I always think it's better to propagate upstream errors from packages:

```
func evalDslExpr(result *Result, dslExpr string) (bool, error) { ... }
```

but since we are already in the output package I think we can keep it this way.

These filtering conditions appears quite powerful also to discriminate which crawling branches abandoning or continue crawling. Shall we track to extend them for this functionality as well in the future? What do you think? (cc @ehsandeep )

Code after:
		if regex.MatchString(event.Request.URL) {
			return true
		}
	}

	return evalDslExpr(event, w.outputMatchCondition)
}

// filterOutput returns true if the event should be filtered out
func (w *StandardWriter) filterOutput(event *Result) bool {
	if w.filterRegex == nil && w.outputFilterCondition == "" {
		return false
	}
	for _, regex := range w.filterRegex {
		if regex.MatchString(event.Request.URL) {
			return true
		}
	}

	return evalDslExpr(event, w.outputFilterCondition)
}

func evalDslExpr(result *Result, dslExpr string) bool {
	resultMap, err := resultToMap(*result)
	if err != nil {
		gologger.Warning().Msgf("Could not map result: %s\n", err)
		return false
	}

	res, err := dsl.EvalExpr(dslExpr, resultMap)
	if err != nil && !ignoreErr(err) {
		gologger.Error().Msgf("Could not evaluate DSL expression: %s\n", err)
		return false
	}
	return res == true
}

func resultToMap(result Result) (map[string]interface{}, error) {
	resultMap := make(map[string]any)
	config := &mapstructure.DecoderConfig{
		TagName: "json",
		Result:  &resultMap,
	}
	decoder, err := mapstructure.NewDecoder(config)
	if err != nil {
		return nil, fmt.Errorf("error creating decoder: %v", err)
	}
	err = decoder.Decode(result)
	if err != nil {
		return nil, fmt.Errorf("error decoding: %v", err)
	}
Repository: projectdiscovery/katana
File: pkg/utils/scope/scope.go (Go)

Code before:
package scope

import (
	"fmt"
	"net"
	"net/url"
	"regexp"
	"strings"

	"golang.org/x/net/publicsuffix"
)

// Manager manages scope for crawling process
type Manager struct {
	inScope           []*regexp.Regexp
	outOfScope        []*regexp.Regexp
	noScope           bool
	fieldScope        dnsScopeField
	fieldScopePattern *regexp.Regexp
}

type dnsScopeField int

const (
	dnDnsScopeField dnsScopeField = iota + 1
	rdnDnsScopeField
	fqdnDNSScopeField
	customDNSScopeField
)

var stringToDNSScopeField = map[string]dnsScopeField{
	"dn":   dnDnsScopeField,
	"rdn":  rdnDnsScopeField,
	"fqdn": fqdnDNSScopeField,
}

// NewManager returns a new scope manager for crawling
func NewManager(inScope, outOfScope []string, fieldScope string, noScope bool) (*Manager, error) {
	manager := &Manager{
		noScope: noScope,
	}

	if scopeValue, ok := stringToDNSScopeField[fieldScope]; !ok {
		//return nil, fmt.Errorf("invalid dns scope field specified: %s", fieldScope)

Review comment (suggestion):
Let's update the README to reflect the changes we're making. 

```
-fs, -field-scope string pre-defined scope field (dn,rdn,fqdn) or custom regex pattern (e.g., '(company-staging.io|company.com)') (default "rdn")
```

Code after:
package scope

import (
	"fmt"
	"net"
	"net/url"
	"regexp"
	"strings"

	"golang.org/x/net/publicsuffix"
)

// Manager manages scope for crawling process
type Manager struct {
	inScope           []*regexp.Regexp
	outOfScope        []*regexp.Regexp
	noScope           bool
	fieldScope        dnsScopeField
	fieldScopePattern *regexp.Regexp
}

type dnsScopeField int

const (
	dnDnsScopeField dnsScopeField = iota + 1
	rdnDnsScopeField
	fqdnDNSScopeField
	customDNSScopeField
)

var stringToDNSScopeField = map[string]dnsScopeField{
	"dn":   dnDnsScopeField,
	"rdn":  rdnDnsScopeField,
	"fqdn": fqdnDNSScopeField,
}

// NewManager returns a new scope manager for crawling
func NewManager(inScope, outOfScope []string, fieldScope string, noScope bool) (*Manager, error) {
	manager := &Manager{
		noScope: noScope,
	}

	if scopeValue, ok := stringToDNSScopeField[fieldScope]; !ok {
		manager.fieldScope = customDNSScopeField